Projekt

Obecné

Profil

Stáhnout (1.13 KB) Statistiky
| Větev: | Tag: | Revize:
1
<?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
    const ORDER_COLUMN = 'page';
13

    
14
    public function __construct()
15
    {
16
        $this->middleware('auth');
17
    }
18

    
19
    /**
20
     * Show list of favourite metadata.
21
     *
22
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
23
     */
24
    public function index()
25
    {
26
        $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

    
32
        return view('favmetadata.index', ['metadata' => $metadata]);
33
    }
34

    
35
    /**
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
}
(6-6/8)