1 |
d7feebff
|
zabran
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace App\Http\Controllers;
|
4 |
|
|
|
5 |
49b1d48f
|
zabran
|
use App\User;
|
6 |
d7feebff
|
zabran
|
use Illuminate\Contracts\Foundation\Application;
|
7 |
|
|
use Illuminate\Contracts\View\Factory;
|
8 |
|
|
use Illuminate\Support\Facades\Auth;
|
9 |
|
|
use App\Artefact;
|
10 |
|
|
use App\Http\Controllers\Image;
|
11 |
|
|
use Illuminate\View\View;
|
12 |
|
|
|
13 |
|
|
class ChartsController extends Controller
|
14 |
|
|
{
|
15 |
|
|
public function __construct()
|
16 |
|
|
{
|
17 |
|
|
$this->middleware('auth');
|
18 |
|
|
}
|
19 |
|
|
|
20 |
|
|
/**
|
21 |
|
|
* Display a listing of the resource.
|
22 |
|
|
*
|
23 |
|
|
* @return Application|Factory|View
|
24 |
|
|
*/
|
25 |
|
|
public function index()
|
26 |
|
|
{
|
27 |
|
|
if(Auth::check())
|
28 |
|
|
{
|
29 |
|
|
$artefacts = Artefact::all();
|
30 |
49b1d48f
|
zabran
|
//$user_likes = User::find(Auth::id())->likesArtefacts();
|
31 |
d7feebff
|
zabran
|
foreach($artefacts as $item)
|
32 |
|
|
{
|
33 |
49b1d48f
|
zabran
|
$id = $item->id;
|
34 |
|
|
$item['likes'] = Artefact::find($id)->users()->count();
|
35 |
|
|
$item['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
|
36 |
d7feebff
|
zabran
|
}
|
37 |
|
|
$artefacts=$artefacts->sortByDesc('likes');
|
38 |
|
|
|
39 |
|
|
$data = array(
|
40 |
|
|
'title' => 'Charts',
|
41 |
|
|
'artefacts' => $artefacts
|
42 |
|
|
);
|
43 |
49b1d48f
|
zabran
|
return view('charts.index') -> with($data);
|
44 |
d7feebff
|
zabran
|
}
|
45 |
|
|
else
|
46 |
|
|
{
|
47 |
|
|
$data = array(
|
48 |
|
|
'title' => 'Welcome to the MERLOT page',
|
49 |
|
|
);
|
50 |
|
|
//return view('index', compact('title'));
|
51 |
|
|
return view('pages.index') -> with($data);
|
52 |
|
|
}
|
53 |
|
|
}
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* Display the specified resource.
|
57 |
|
|
*
|
58 |
|
|
* @return Application|Factory|View
|
59 |
|
|
*/
|
60 |
|
|
public function show()
|
61 |
|
|
{
|
62 |
|
|
$artefacts = Artefact::all();
|
63 |
49b1d48f
|
zabran
|
//$user_likes = User::find(Auth::id())->likesArtefacts();
|
64 |
d7feebff
|
zabran
|
foreach($artefacts as $item)
|
65 |
|
|
{
|
66 |
49b1d48f
|
zabran
|
$id = $item->id;
|
67 |
|
|
$item['likes'] = Artefact::find($id)->users()->count();
|
68 |
|
|
$item['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
|
69 |
d7feebff
|
zabran
|
}
|
70 |
|
|
$artefacts=$artefacts->sortByDesc('likes');
|
71 |
|
|
|
72 |
|
|
$data = array(
|
73 |
|
|
'title' => 'Charts',
|
74 |
|
|
'artefacts' => $artefacts
|
75 |
|
|
);
|
76 |
|
|
return view('charts.index') -> with($data);
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
}
|