Authenticate::handle()   A
last analyzed

Complexity

Conditions 3
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.4285
cc 3
eloc 7
nc 3
nop 2
1
<?php namespace App\Http\Middleware;
2
3
use Closure;
4
use Illuminate\Contracts\Auth\Guard;
5
6
class Authenticate {
7
8
	/**
9
	 * The Guard implementation.
10
	 *
11
	 * @var Guard
12
	 */
13
	protected $auth;
14
15
	/**
16
	 * Create a new filter instance.
17
	 *
18
	 * @param  Guard  $auth
19
	 */
20
	public function __construct(Guard $auth)
21
	{
22
		$this->auth = $auth;
23
	}
24
25
	/**
26
	 * Handle an incoming request.
27
	 *
28
	 * @param  \Illuminate\Http\Request  $request
29
	 * @param  \Closure  $next
30
	 * @return mixed
31
	 */
32
	public function handle($request, Closure $next)
33
	{
34
		if ($this->auth->guest())
35
		{
36
			if ($request->ajax())
37
			{
38
				return response('Unauthorized.', 401);
39
			}
40
			else
41
			{
42
				return redirect()->guest('/');
43
			}
44
		}
45
46
		return $next($request);
47
	}
48
49
}
50