Completed
Push — master ( dd0ca4...f00659 )
by Julien
03:18
created

Authorisation::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
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 9
rs 9.6667
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Illuminate\Contracts\Auth\Guard;
7
use Illuminate\Support\Facades\Auth;
8
use Illuminate\Support\Facades\Redirect;
9
10
class Authorisation
11
{
12
    /**
13
     * The Guard implementation.
14
     *
15
     * @var Guard
16
     */
17
    protected $auth;
18
19
    /**
20
     * Create a new filter instance.
21
     *
22
     * @param  Guard  $auth
23
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
24
     */
25
    public function __construct(Guard $auth)
26
    {
27
        $this->auth = $auth;
28
    }
29
30
    /**
31
     * Handle an incoming request.
32
     *
33
     * @param  \Illuminate\Http\Request  $request
34
     * @param  \Closure  $next
35
     * @return mixed
36
     */
37
    public function handle(\Illuminate\Http\Request $request, Closure $next)
38
    {
39
        if (Auth::user()->cannot('isSuperAdmin', Auth::user())) {
40
41
            return Redirect::to('auth/login')->with('danger', "Vous n'etes pas authoriser a acéder à cette partie :(");
42
        }
43
44
        return $next($request);
45
    }
46
}
47