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 |
f49916cc
|
zabran
|
$artefacts = Artefact::withCount('users')->orderByDesc('users_count')->get()->take(10);
|
30 |
d7feebff
|
zabran
|
foreach($artefacts as $item)
|
31 |
|
|
{
|
32 |
49b1d48f
|
zabran
|
$id = $item->id;
|
33 |
|
|
$item['likes'] = Artefact::find($id)->users()->count();
|
34 |
|
|
$item['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
|
35 |
d7feebff
|
zabran
|
}
|
36 |
|
|
|
37 |
|
|
$data = array(
|
38 |
|
|
'title' => 'Charts',
|
39 |
|
|
'artefacts' => $artefacts
|
40 |
|
|
);
|
41 |
49b1d48f
|
zabran
|
return view('charts.index') -> with($data);
|
42 |
d7feebff
|
zabran
|
}
|
43 |
|
|
else
|
44 |
|
|
{
|
45 |
|
|
$data = array(
|
46 |
|
|
'title' => 'Welcome to the MERLOT page',
|
47 |
|
|
);
|
48 |
|
|
//return view('index', compact('title'));
|
49 |
|
|
return view('pages.index') -> with($data);
|
50 |
|
|
}
|
51 |
|
|
}
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* Display the specified resource.
|
55 |
|
|
*
|
56 |
|
|
* @return Application|Factory|View
|
57 |
|
|
*/
|
58 |
947493de
|
zabran
|
/*public function show()
|
59 |
d7feebff
|
zabran
|
{
|
60 |
|
|
$artefacts = Artefact::all();
|
61 |
49b1d48f
|
zabran
|
//$user_likes = User::find(Auth::id())->likesArtefacts();
|
62 |
d7feebff
|
zabran
|
foreach($artefacts as $item)
|
63 |
|
|
{
|
64 |
49b1d48f
|
zabran
|
$id = $item->id;
|
65 |
|
|
$item['likes'] = Artefact::find($id)->users()->count();
|
66 |
|
|
$item['favourite'] = is_null(User::find(Auth::id())->likesArtefacts()->find($id)) ? false : true;
|
67 |
d7feebff
|
zabran
|
}
|
68 |
|
|
$artefacts=$artefacts->sortByDesc('likes');
|
69 |
|
|
|
70 |
|
|
$data = array(
|
71 |
|
|
'title' => 'Charts',
|
72 |
|
|
'artefacts' => $artefacts
|
73 |
|
|
);
|
74 |
|
|
return view('charts.index') -> with($data);
|
75 |
947493de
|
zabran
|
}*/
|
76 |
d7feebff
|
zabran
|
|
77 |
|
|
}
|