Completed
Push — master ( 95beae...9b5f81 )
by ARCANEDEV
03:58
created

CheckAdministrators   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
dl 0
loc 50
rs 10
c 0
b 0
f 0
ccs 0
cts 11
cp 0
wmc 4
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 10 3
1
<?php namespace Arcanesoft\Core\Http\Middleware;
2
3
use Closure;
4
use Illuminate\Http\Request;
5
use Illuminate\Contracts\Auth\Factory as Auth;
6
7
/**
8
 * Class     AdminMiddleware
9
 *
10
 * @package  Arcanesoft\Foundation\Http\Middleware
11
 * @author   ARCANEDEV <[email protected]>
12
 */
13
class CheckAdministrators
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Properties
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * The authentication factory instance.
21
     *
22
     * @var \Illuminate\Contracts\Auth\Factory
23
     */
24
    protected $auth;
25
26
    /* ------------------------------------------------------------------------------------------------
27
     |  Constructor
28
     | ------------------------------------------------------------------------------------------------
29
     */
30
    /**
31
     * Create a new middleware instance.
32
     *
33
     * @param  \Illuminate\Contracts\Auth\Factory  $auth
34
     */
35
    public function __construct(Auth $auth)
36
    {
37
        $this->auth = $auth;
38
    }
39
40
    /* ------------------------------------------------------------------------------------------------
41
     |  Main Functions
42
     | ------------------------------------------------------------------------------------------------
43
     */
44
    /**
45
     * Run the request filter.
46
     *
47
     * @param  \Illuminate\Http\Request  $request
48
     * @param  \Closure                  $next
49
     *
50
     * @return mixed
51
     */
52
    public function handle(Request $request, Closure $next)
53
    {
54
        /** @var  \Arcanesoft\Contracts\Auth\Models\User  $user */
55
        $user = $this->auth->guard()->user();
56
57
        if (is_null($user) || ! $user->isAdmin())
58
            abort(404, "You're not allowed !");
59
60
        return $next($request);
61
    }
62
}
63