Authenticate   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 7 2
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Factory as Auth;
7
8
class Authenticate
9
{
10
    /**
11
     * The authentication guard factory instance.
12
     *
13
     * @var \Illuminate\Contracts\Auth\Factory
14
     */
15
    protected $auth;
16
17
    /**
18
     * Create a new middleware instance.
19
     *
20
     * @param \Illuminate\Contracts\Auth\Factory $auth
21
     *
22
     * @return void
23
     */
24
    public function __construct(Auth $auth)
25
    {
26
        $this->auth = $auth;
27
    }
28
29
    /**
30
     * Handle an incoming request.
31
     *
32
     * @param \Illuminate\Http\Request $request
33
     * @param \Closure                 $next
34
     * @param string|null              $guard
35
     *
36
     * @return mixed
37
     */
38
    public function handle($request, Closure $next, $guard = null)
39
    {
40
        if ($this->auth->guard($guard)->guest()) {
41
            return response('Unauthorized.', 401);
42
        }
43
44
        return $next($request);
45
    }
46
}
47