ArticlesController::show()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 2
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of laravel.su package.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
declare(strict_types=1);
10
11
namespace App\Http\Controllers;
12
13
use App\Models\Article;
14
use Illuminate\Contracts\View\View;
15
use Illuminate\Contracts\Auth\Guard;
16
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
17
18
/**
19
 * Class ArticlesController.
20
 */
21
class ArticlesController extends Controller
22
{
23
    /**
24
     * @return View
25
     */
26
    public function index(): View
27
    {
28
        return view('page.articles.index', [
29
            'articles' => Article::latestPublished()->paginate(10),
30
        ]);
31
    }
32
33
    /**
34
     * @param  string $slug
35
     * @param  Guard  $guard
36
     * @return string
37
     *
38
     * @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
39
     * @throws
40
     */
41
    public function show(string $slug, Guard $guard)
42
    {
43
        /** @var Article $article */
44
        $article = Article::where('slug', $slug)->firstOrFail();
45
46
        if (! $article->isAllowedForUser($guard->user())) {
47
            throw new AccessDeniedHttpException('Article [' . $article->slug . '] are not allowed for view');
48
        }
49
50
        return view('page.articles.show', [
51
            'article' => $article,
52
        ]);
53
    }
54
55
    /**
56
     * @param $id
57
     * @return mixed
58
     */
59
    public function indexForTag($id)
60
    {
61
        return $id;
62
    }
63
}
64