Projekt

Obecné

Profil

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

    
3
namespace App\Http\Controllers;
4

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

    
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
     * @return Application|Factory|View
24
     */
25
    public function index()
26
    {
27
        if(Auth::check())
28
        {
29
            $id = Auth::id();
30
            $artefacts = User::find($id)->likesArtefacts()->get();
31
            foreach($artefacts as $item)
32
            {
33
                $item['likes'] = Artefact::find($item->id)->users()->count();
34
            }
35

    
36
            $data = array(
37
                'title' => 'Favorite artefacts',
38
                'user' => $id,
39
                'artefacts' => $artefacts
40
            );
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
     * @return Application|Factory|View
58
     */
59
    public function show($id)
60
    {
61
        $artefacts = User::find($id)->likesArtefacts()->get();
62
        foreach($artefacts as $item)
63
        {
64
            $item['likes'] = Artefact::find($item->id)->users()->count();
65
        }
66

    
67
        $data = array(
68
            'title' => 'Favorite artefacts',
69
            'id' => $id,
70
            'user' => User::find($id),
71
            'userId' => Auth::id(),
72
            'artefacts' => $artefacts
73
        );
74
        return view('favartefacts.index') -> with($data);
75
    }
76

    
77
}
(6-6/10)