Projekt

Obecné

Profil

Stáhnout (1.39 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?php
2

    
3
namespace App\Http\Controllers;
4

    
5
use App\User;
6
use Illuminate\Contracts\Foundation\Application;
7
use Illuminate\Contracts\View\Factory;
8
use Illuminate\Http\RedirectResponse;
9
use Illuminate\Support\Facades\Auth;
10
use App\Http\Controllers\Image;
11
use Illuminate\View\View;
12
use App\Artefact;
13

    
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
            $artefacts = Artefact::withCount('users')->orderByDesc('users_count')->get()->take(10);
31
            foreach($artefacts as $item)
32
            {
33
                $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
            }
37

    
38
            $data = array(
39
                'title' => 'Charts',
40
                'artefacts' => $artefacts
41
            );
42
            return view('charts.index') -> with($data);
43
        }
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
}
(3-3/10)