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(isset(Auth::user()->id))
|
25
|
{
|
26
|
$userId = Auth::user()->id;
|
27
|
$list = ArtefactUser::where('user_id', $userId)->get();
|
28
|
$finalData = array();
|
29
|
foreach($list as $item)
|
30
|
{
|
31
|
array_push($finalData, Artefact::where('id', $item->artefact_id)->get());
|
32
|
}
|
33
|
|
34
|
$data = array(
|
35
|
'title' => 'Favorite artefacts',
|
36
|
'user' => User::find($userId),
|
37
|
'artefacts' => $finalData
|
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
|
$list = ArtefactUser::where('user_id', $id)->get();
|
60
|
$finalData = array();
|
61
|
foreach($list as $item)
|
62
|
{
|
63
|
array_push($finalData, Artefact::where('id', $item->artefact_id)->get());
|
64
|
}
|
65
|
|
66
|
$data = array(
|
67
|
'title' => 'Favorite artefacts',
|
68
|
'id' => $id,
|
69
|
'user' => User::find($id),
|
70
|
'userId' => Auth::user()->id,
|
71
|
'artefacts' => $finalData
|
72
|
);
|
73
|
return view('favartefacts.index') -> with($data);
|
74
|
}
|
75
|
|
76
|
}
|