BackendAuthorize   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 7
c 1
b 1
f 1
dl 0
loc 22
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 4
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use App\Http\Requests\Request;
6
use Illuminate\Auth\AuthenticationException;
7
8
class BackendAuthorize
9
{
10
    /**
11
     * @param Request $request
12
     * @param         $next
13
     *
14
     * @throws AuthenticationException
15
     *
16
     * @return \Illuminate\Http\RedirectResponse
17
     */
18
    public function handle($request, $next)
19
    {
20
        $user = $request->user();
21
        if ($user && $user->hasRole('admin')) {
22
            return $next($request);
23
        }
24
25
        if ($request->wantsJson()) {
26
            throw new AuthenticationException();
27
        }
28
29
        return redirect(route('home'))->withErrors('You do not have privilege access this page');
30
    }
31
}
32