Completed
Push — master ( 092870...dbc3bd )
by Mahmoud
04:24
created

EntrustRoleForWeb::handle()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 3
eloc 4
nc 2
nop 3
1
<?php
2
3
namespace App\Containers\Authorization\Middlewares;
4
5
use App\Port\Butler\Portals\PortButler;
6
use Closure;
7
use Illuminate\Contracts\Auth\Guard;
8
9
class EntrustRoleForWeb
10
{
11
12
    protected $auth;
13
14
    /**
15
     * @var  \App\Port\Butler\Portals\PortButler
16
     */
17
    private $portButler;
18
19
    /**
20
     * Creates a new instance of the middleware.
21
     *
22
     * @param Guard $auth
23
     */
24
    public function __construct(Guard $auth, PortButler $portButler)
25
    {
26
        $this->auth = $auth;
27
        $this->portButler = $portButler;
28
    }
29
30
    /**
31
     * Handle an incoming request.
32
     *
33
     * @param  \Illuminate\Http\Request $request
34
     * @param  Closure                  $next
35
     * @param                           $roles
36
     *
37
     * @return mixed
38
     */
39
    public function handle($request, Closure $next, $roles)
40
    {
41
        if ($this->auth->guest() || !$request->user()->hasRole(explode('|', $roles))) {
42
            return view($this->portButler->getLoginWebPageName());
43
        }
44
45
        return $next($request);
46
    }
47
}
48