Projekt

Obecné

Profil

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