Projekt

Obecné

Profil

Stáhnout (2.12 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\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
            //$user_likes = User::find(Auth::id())->likesArtefacts();
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
            $artefacts=$artefacts->sortByDesc('likes');
38

    
39
            $data = array(
40
                'title' => 'Charts',
41
                'artefacts' => $artefacts
42
            );
43
            return view('charts.index') -> with($data);
44
        }
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
        //$user_likes = User::find(Auth::id())->likesArtefacts();
64
        foreach($artefacts as $item)
65
        {
66
            $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
        }
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
}
(3-3/10)