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 |
4c56c41b
|
zabran
|
use Illuminate\Http\RedirectResponse;
|
9 |
d7feebff
|
zabran
|
use Illuminate\Support\Facades\Auth;
|
10 |
|
|
use App\Http\Controllers\Image;
|
11 |
|
|
use Illuminate\View\View;
|
12 |
4c56c41b
|
zabran
|
use App\Artefact;
|
13 |
d7feebff
|
zabran
|
|
14 |
|
|
class ChartsController extends Controller
|
15 |
|
|
{
|
16 |
|
|
public function __construct()
|
17 |
|
|
{
|
18 |
|
|
$this->middleware('auth');
|
19 |
|
|
}
|
20 |
|
|
|
21 |
|
|
/**
|
22 |
|
|
* Display a listing of the resource.
|
23 |
|
|
*
|
24 |
|
|
* @return Application|Factory|View
|
25 |
|
|
*/
|
26 |
|
|
public function index()
|
27 |
|
|
{
|
28 |
|
|
if(Auth::check())
|
29 |
|
|
{
|
30 |
f49916cc
|
zabran
|
$artefacts = Artefact::withCount('users')->orderByDesc('users_count')->get()->take(10);
|
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 |
|
|
|
38 |
|
|
$data = array(
|
39 |
|
|
'title' => 'Charts',
|
40 |
|
|
'artefacts' => $artefacts
|
41 |
|
|
);
|
42 |
49b1d48f
|
zabran
|
return view('charts.index') -> with($data);
|
43 |
d7feebff
|
zabran
|
}
|
44 |
|
|
else
|
45 |
|
|
{
|
46 |
|
|
$data = array(
|
47 |
|
|
'title' => 'Welcome to the MERLOT page',
|
48 |
|
|
);
|
49 |
|
|
//return view('index', compact('title'));
|
50 |
|
|
return view('pages.index') -> with($data);
|
51 |
|
|
}
|
52 |
|
|
}
|
53 |
|
|
|
54 |
|
|
|
55 |
|
|
}
|