Projekt

Obecné

Profil

Stáhnout (1.81 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?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
use App\Http\Controllers\Image;
10

    
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
        if(Auth::check())
26
        {
27
            $id = Auth::id();
28
            $artefacts = User::find($id)->likesArtefacts()->get();
29
            foreach($artefacts as $item)
30
            {
31
                $item['likes'] = Artefact::find($item->id)->users()->count();
32
            }
33

    
34
            $data = array(
35
                'title' => 'Favorite artefacts',
36
                'user' => $id,
37
                'artefacts' => $artefacts
38
            );
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
        $artefacts = User::find($id)->likesArtefacts()->get();
60
        foreach($artefacts as $item)
61
        {
62
            $item['likes'] = Artefact::find($item->id)->users()->count();
63
        }
64

    
65

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

    
76
}
(5-5/8)