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

CBSuperadmin::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 3
nop 2
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
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