Projekt

Obecné

Profil

Stáhnout (2.14 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
        if(isset(Auth::user()->id))
26
        {
27
            $userId = Auth::user()->id;
28
            $list = ArtefactUser::where('user_id', $userId)->get();
29
            $finalData = array();
30
            foreach($list as $item)
31
            {
32 4c3f70c4 rizir01
                $tmp = Artefact::where('id', $item->artefact_id)->get();
33
                $tmp['likes'] = Artefact::find($item->artefact_id)->users()->count();
34
                array_push($finalData, $tmp);
35 120e7c58 rizir01
            }
36
37
            $data = array(
38
                'title' => 'Favorite artefacts',
39
                'user' => User::find($userId),
40
                'artefacts' => $finalData
41
            );
42
            return view('favartefacts.index') -> with($data);
43
        }
44
        else
45
        {
46
            $data = array(
47
                'title' => 'Welcome to the MERLOT page',
48
            );
49
            //return view('index', compact('title'));
50
            return view('pages.index') -> with($data);
51
        }
52
    }
53
54
    /**
55
     * Display the specified resource.
56
     *
57
     * @param  int  $id
58
     * @return \Illuminate\Http\Response
59
     */
60
    public function show($id)
61
    {
62
        $list = ArtefactUser::where('user_id', $id)->get();
63
        $finalData = array();
64
        foreach($list as $item)
65
        {
66 4c3f70c4 rizir01
            $tmp = Artefact::where('id', $item->artefact_id)->get();
67
            $tmp['likes'] = Artefact::find($item->artefact_id)->users()->count();
68
            array_push($finalData, $tmp);
69 120e7c58 rizir01
        }
70
71
        $data = array(
72
            'title' => 'Favorite artefacts',
73
            'id' => $id,
74
            'user' => User::find($id),
75
            'userId' => Auth::user()->id,
76
            'artefacts' => $finalData
77
        );
78
        return view('favartefacts.index') -> with($data);
79
    }
80
81
}