AdminMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
eloc 8
c 1
b 0
f 1
dl 0
loc 15
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 3
1
<?php
2
3
namespace Mongi\Mongicommerce\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8
class AdminMiddleware
9
{
10
    public function handle($request, Closure $next)
11
    {
12
        if (!Auth::check()) {
13
            // I included this check because you have it, but it really should be part of your 'auth' middleware, most likely added as part of a route group.
14
            return redirect(route('admin.login'));
15
        }
16
        // Perform action
17
        $user = Auth::user();
18
19
        if ($user->admin == true) {
0 ignored issues
show
Bug introduced by
Accessing admin on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
20
            return $next($request);
21
        } else {
22
            abort(403);
23
        }
24
    }
25
}
26