1 |
09795926
|
Adam Mištera
|
<?php
|
2 |
|
|
|
3 |
|
|
namespace App\Http\Controllers;
|
4 |
|
|
|
5 |
|
|
use App\Metadata;
|
6 |
|
|
use App\User;
|
7 |
|
|
use Illuminate\Http\Request;
|
8 |
|
|
use Illuminate\Support\Facades\Auth;
|
9 |
|
|
|
10 |
|
|
class FavoriteMetadataController extends Controller
|
11 |
|
|
{
|
12 |
3c062db9
|
Adam Mištera
|
const ORDER_COLUMN = 'page';
|
13 |
|
|
|
14 |
09795926
|
Adam Mištera
|
public function __construct()
|
15 |
|
|
{
|
16 |
|
|
$this->middleware('auth');
|
17 |
|
|
}
|
18 |
|
|
|
19 |
26e128a8
|
Adam Mištera
|
/**
|
20 |
|
|
* Show list of favourite metadata.
|
21 |
|
|
*
|
22 |
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
|
23 |
|
|
*/
|
24 |
09795926
|
Adam Mištera
|
public function index()
|
25 |
|
|
{
|
26 |
3c062db9
|
Adam Mištera
|
$metadata = User::find(Auth::id())->likesMetadata()->orderBy(self::ORDER_COLUMN)->get();
|
27 |
|
|
foreach($metadata as $item)
|
28 |
|
|
{
|
29 |
|
|
$item['artefact'] = Metadata::find($item->id)->artefact()->first();
|
30 |
|
|
}
|
31 |
09795926
|
Adam Mištera
|
|
32 |
|
|
return view('favmetadata.index', ['metadata' => $metadata]);
|
33 |
|
|
}
|
34 |
|
|
|
35 |
26e128a8
|
Adam Mištera
|
/**
|
36 |
|
|
* Unlike metadata given by its id.
|
37 |
|
|
*
|
38 |
|
|
* @param $id int id of metadata
|
39 |
|
|
* @return \Illuminate\Http\RedirectResponse
|
40 |
|
|
*/
|
41 |
|
|
public function unlike($id)
|
42 |
|
|
{
|
43 |
|
|
$user = User::find(Auth::id());
|
44 |
|
|
$metadata = Metadata::find($id);
|
45 |
|
|
|
46 |
|
|
$user->likesMetadata()->detach($metadata);
|
47 |
|
|
|
48 |
|
|
return back()->withInput();
|
49 |
|
|
}
|
50 |
|
|
|
51 |
09795926
|
Adam Mištera
|
}
|