Completed
Push — master ( ac6145...bdf07d )
by Şəhriyar
14:49
created

Authenticate::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php namespace App\Http\Middleware;
2
3
use Illuminate\Contracts\Auth\Guard;
4
use Illuminate\Http\Request;
5
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
6
7
class Authenticate
8
{
9
    /**
10
     * The Guard implementation.
11
     *
12
     * @var Guard
13
     */
14
    protected $auth;
15
16
    /**
17
     * Create a new filter instance.
18
     *
19
     * @param  Guard $auth
20
     */
21 2
    public function __construct(Guard $auth)
22
    {
23 2
        $this->auth = $auth;
24 2
    }
25
26
    /**
27
     * Handle an incoming request.
28
     *
29
     * @param  Request  $request
30
     * @param  \Closure $next
31
     *
32
     * @return mixed
33
     */
34 2
    public function handle(Request $request, \Closure $next)
35
    {
36 2
        if (app('sentinel')->guest()) {
37 1
            if ($request->ajax() || $request->wantsJson()) {
38 1
                throw new UnauthorizedHttpException('Unauthorized');
39
            } else {
40
                return redirect()->guest(route('login'));
41
            }
42
        }
43
44 1
        return $next($request);
45
    }
46
}
47