aswi2020merlot-gitlab/app/Http/Controllers/FavoriteArtefactsController.php @ 82b213a0
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 |
|
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 |
if(Auth::check()) |
25 |
{
|
26 |
$artefacts = User::find(Auth::id())->likesArtefacts()->get(); |
27 |
|
28 |
$data = array( |
29 |
'title' => 'Favorite artefacts', |
30 |
'user' => Auth::user(), |
31 |
'artefacts' => $artefacts |
32 |
);
|
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 |
$artefacts = []; |
54 |
if (!is_null(User::find($id))) |
55 |
{
|
56 |
$artefacts = User::find($id)->likesArtefacts()->get(); |
57 |
}
|
58 |
|
59 |
$data = array( |
60 |
'title' => 'Favorite artefacts', |
61 |
'id' => $id, |
62 |
'user' => Auth::user(), |
63 |
'userId' => Auth::id(), |
64 |
'artefacts' => $artefacts |
65 |
);
|
66 |
return view('favartefacts.index') -> with($data); |
67 |
}
|
68 |
|
69 |
}
|