Authenticate   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handleUnauthorizedRequest() 0 8 2
A handle() 0 10 2
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
7
class Authenticate
8
{
9
    public function handle($request, Closure $next)
10
    {
11
        if (! current_user()) {
12
            return $this->handleUnauthorizedRequest($request);
13
        }
14
15
        current_user()->registerLastActivity()->save();
16
17
        return $next($request);
18
    }
19
20
    protected function handleUnauthorizedRequest($request)
21
    {
22
        if ($request->ajax()) {
23
            return response('Unauthorized.', 401);
24
        }
25
26
        return redirect()->guest(login_url());
27
    }
28
}
29