Passed
Push — master ( 41c09c...5f5681 )
by Iman
06:15
created

CBSuperadmin   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 13 3
1
<?php
2
3
namespace crocodicstudio\crudbooster\CBCoreModule\middlewares;
4
5
use Closure;
6
use crocodicstudio\crudbooster\helpers\CRUDBooster;
7
8
class CBSuperadmin
9
{
10
    /**
11
     * Handle an incoming request.
12
     *
13
     * @param  \Illuminate\Http\Request  $request
14
     * @param  \Closure  $next
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next)
18
    {   
19
        $adminPath = cbConfig('ADMIN_PATH', 'admin');
20
21
        if (auth('cbAdmin')->guest()) {
22
            return redirect(url($adminPath.'/login'))->with('message', cbTrans('not_logged_in'));
23
        }
24
25
        if(!CRUDBooster::isSuperadmin()) {
26
            return redirect($adminPath)->with(['message'=> cbTrans('denied_access'),'message_type'=>'warning']);
27
        }
28
29
        return $next($request);
30
    }
31
}
32