Authenticate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 23
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 4
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Auth;
7
8
class Authenticate
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  \Closure  $next
15
     * @param  string|null  $guard
16
     * @return mixed
17
     */
18
    public function handle($request, Closure $next, $guard = null)
19
    {
20
        if (Auth::guard($guard)->guest()) {
21
            if ($request->ajax() || $request->wantsJson()) {
22
                return response('Unauthorized.', 401);
23
            } else {
24
                return redirect()->guest('login');
25
            }
26
        }
27
28
        return $next($request);
29
    }
30
}
31