RoleMiddleware   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 24
c 0
b 0
f 0
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 15 4
1
<?php
2
3
namespace Thinktomorrow\Chief\App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8
class RoleMiddleware
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  \Closure  $next
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next, $role, $permission)
18
    {
19
        if (Auth::guest()) {
20
            return redirect('/');
21
        }
22
23
        if (! $request->user('chief')->hasRole($role)) {
24
            abort(403);
25
        }
26
27
        if (! $request->user('chief')->can($permission)) {
28
            abort(403);
29
        }
30
31
        return $next($request);
32
    }
33
}
34