Administrator::handle()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.2
cc 4
eloc 7
nc 3
nop 2
1
<?php namespace App\Http\Middleware;
2
3
use Closure;
4
use Illuminate\Auth\Guard;
5
6
class Administrator {
7
8
    protected $auth;
9
10
    public function __construct(Guard $auth)
11
    {
12
        $this->auth = $auth;
13
    }
14
15
	public function handle($request, Closure $next)
16
	{
17
        if ($this->auth->guest() || session('role')!=='ADMN' )
18
        {
19
            if ($request->ajax())
20
            {
21
                return response('Unauthorized.', 401);
22
            }
23
            else
24
            {
25
                return redirect()->guest('/');
26
            }
27
        }
28
29
		return $next($request);
30
	}
31
32
}
33