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 |
|
|
|
10 |
|
|
class FavoriteArtefactsController extends Controller
|
11 |
|
|
{
|
12 |
|
|
public function __construct()
|
13 |
|
|
{
|
14 |
|
|
$this->middleware('auth');
|
15 |
|
|
}
|
16 |
|
|
|
17 |
|
|
/**
|
18 |
|
|
* Display a listing of the resource.
|
19 |
|
|
*
|
20 |
|
|
* @return \Illuminate\Http\Response
|
21 |
|
|
*/
|
22 |
|
|
public function index()
|
23 |
|
|
{
|
24 |
09795926
|
Adam Mištera
|
if(Auth::check())
|
25 |
120e7c58
|
rizir01
|
{
|
26 |
09795926
|
Adam Mištera
|
$artefacts = User::find(Auth::id())->likesArtefacts()->get();
|
27 |
120e7c58
|
rizir01
|
|
28 |
|
|
$data = array(
|
29 |
|
|
'title' => 'Favorite artefacts',
|
30 |
09795926
|
Adam Mištera
|
'user' => Auth::user(),
|
31 |
|
|
'artefacts' => $artefacts
|
32 |
120e7c58
|
rizir01
|
);
|
33 |
|
|
return view('favartefacts.index') -> with($data);
|
34 |
|
|
}
|
35 |
|
|
else
|
36 |
|
|
{
|
37 |
|
|
$data = array(
|
38 |
|
|
'title' => 'Welcome to the MERLOT page',
|
39 |
|
|
);
|
40 |
|
|
//return view('index', compact('title'));
|
41 |
|
|
return view('pages.index') -> with($data);
|
42 |
|
|
}
|
43 |
|
|
}
|
44 |
|
|
|
45 |
|
|
/**
|
46 |
|
|
* Display the specified resource.
|
47 |
|
|
*
|
48 |
|
|
* @param int $id
|
49 |
|
|
* @return \Illuminate\Http\Response
|
50 |
|
|
*/
|
51 |
|
|
public function show($id)
|
52 |
|
|
{
|
53 |
09795926
|
Adam Mištera
|
$artefacts = [];
|
54 |
|
|
if (!is_null(User::find($id)))
|
55 |
120e7c58
|
rizir01
|
{
|
56 |
09795926
|
Adam Mištera
|
$artefacts = User::find($id)->likesArtefacts()->get();
|
57 |
120e7c58
|
rizir01
|
}
|
58 |
|
|
|
59 |
|
|
$data = array(
|
60 |
|
|
'title' => 'Favorite artefacts',
|
61 |
|
|
'id' => $id,
|
62 |
09795926
|
Adam Mištera
|
'user' => Auth::user(),
|
63 |
|
|
'userId' => Auth::id(),
|
64 |
|
|
'artefacts' => $artefacts
|
65 |
120e7c58
|
rizir01
|
);
|
66 |
|
|
return view('favartefacts.index') -> with($data);
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
}
|