Completed
Push — master ( ae3446...a9781c )
by Mahmoud
06:03
created

LaratrustRoleForWeb   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 8 3
1
<?php
2
3
namespace App\Containers\Authorization\Middlewares;
4
5
use App\Port\Foundation\Portals\PortButler;
6
use Closure;
7
use Illuminate\Contracts\Auth\Guard;
8
use Illuminate\Http\Request;
9
10
/**
11
 * Class LaratrustRoleForWeb
12
 *
13
 * @author  Mahmoud Zalt  <[email protected]>
14
 */
15
class LaratrustRoleForWeb
16
{
17
18
    /**
19
     * @var  \Illuminate\Contracts\Auth\Guard
20
     */
21
    protected $auth;
22
23
    /**
24
     * @var  \App\Port\Foundation\Portals\PortButler
25
     */
26
    private $portButler;
27
28
    /**
29
     * Creates a new instance of the middleware.
30
     *
31
     * @param Guard                               $auth
32
     * @param \App\Port\Foundation\Portals\PortButler $portButler
33
     */
34
    public function __construct(Guard $auth, PortButler $portButler)
35
    {
36
        $this->auth = $auth;
37
        $this->portButler = $portButler;
38
    }
39
40
    /**
41
     * Handle an incoming request.
42
     *
43
     * @param  \Illuminate\Http\Request $request
44
     * @param  Closure                  $next
45
     * @param                           $roles
46
     *
47
     * @return mixed
48
     */
49
    public function handle(Request $request, Closure $next, $roles)
50
    {
51
        if ($this->auth->guest() || !$request->user()->hasRole(explode('|', $roles))) {
52
            return view($this->portButler->getLoginWebPageName());
53
        }
54
55
        return $next($request);
56
    }
57
}
58