Projekt

Obecné

Profil

Stáhnout (1.89 KB) Statistiky
| Větev: | Tag: | Revize:
1 120e7c58 rizir01
<?php
2
3
namespace App\Http\Controllers;
4
5 2fee1bb5 Marek Lovčí
use Illuminate\Contracts\Foundation\Application;
6
use Illuminate\Contracts\View\Factory;
7 120e7c58 rizir01
use Illuminate\Support\Facades\Auth;
8
use App\User;
9
use App\Artefact;
10 4c3f70c4 rizir01
use App\Http\Controllers\Image;
11 2fee1bb5 Marek Lovčí
use Illuminate\View\View;
12 120e7c58 rizir01
13
class FavoriteArtefactsController extends Controller
14
{
15
    public function __construct()
16
    {
17
        $this->middleware('auth');
18
    }
19
20
    /**
21
     * Display a listing of the resource.
22
     *
23 2fee1bb5 Marek Lovčí
     * @return Application|Factory|View
24 120e7c58 rizir01
     */
25
    public function index()
26
    {
27 09795926 Adam Mištera
        if(Auth::check())
28 120e7c58 rizir01
        {
29 b56b3d9b Adam Mištera
            $id = Auth::id();
30
            $artefacts = User::find($id)->likesArtefacts()->get();
31
            foreach($artefacts as $item)
32 120e7c58 rizir01
            {
33 b56b3d9b Adam Mištera
                $item['likes'] = Artefact::find($item->id)->users()->count();
34 120e7c58 rizir01
            }
35
36
            $data = array(
37
                'title' => 'Favorite artefacts',
38 b56b3d9b Adam Mištera
                'user' => $id,
39
                'artefacts' => $artefacts
40 120e7c58 rizir01
            );
41
            return view('favartefacts.index') -> with($data);
42
        }
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
     * @param  int  $id
57 2fee1bb5 Marek Lovčí
     * @return Application|Factory|View
58 120e7c58 rizir01
     */
59
    public function show($id)
60
    {
61 b56b3d9b Adam Mištera
        $artefacts = User::find($id)->likesArtefacts()->get();
62
        foreach($artefacts as $item)
63 120e7c58 rizir01
        {
64 b56b3d9b Adam Mištera
            $item['likes'] = Artefact::find($item->id)->users()->count();
65 120e7c58 rizir01
        }
66
67
        $data = array(
68
            'title' => 'Favorite artefacts',
69
            'id' => $id,
70
            'user' => User::find($id),
71 b56b3d9b Adam Mištera
            'userId' => Auth::id(),
72
            'artefacts' => $artefacts
73 120e7c58 rizir01
        );
74
        return view('favartefacts.index') -> with($data);
75
    }
76
77
}