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

CheckAdministrators::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 3
cp 0
crap 2
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