| Conditions | 8 |
| Paths | 26 |
| Total Lines | 33 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | public function handle($request, Closure $next, $permission, $guard = null) |
||
| 28 | { |
||
| 29 | if (is_null($guard)) { |
||
| 30 | $guard = config('auth.defaults.guard'); |
||
| 31 | } |
||
| 32 | |||
| 33 | //guests are not allowed |
||
| 34 | if (app('auth')->guard($guard)->guest()) { |
||
| 35 | throw UnauthorizedException::notLoggedIn(); |
||
| 36 | } |
||
| 37 | |||
| 38 | $permissions = is_array($permission) ? $permission : explode('|', $permission); |
||
| 39 | |||
| 40 | foreach ($permissions as $permission) { |
||
| 41 | |||
| 42 | // split elements using dot-notation |
||
| 43 | $parts = explode('.', $permission); |
||
| 44 | $ability = ''; |
||
| 45 | |||
| 46 | foreach ($parts as $part) { |
||
| 47 | // reassemble and check each tier |
||
| 48 | $ability .= $ability ? '.' . $part : $part; |
||
| 49 | |||
| 50 | if (app('auth')->guard($guard)->user()->can($ability)) { |
||
| 51 | //exit on first match |
||
| 52 | return $next($request); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | } |
||
| 56 | |||
| 57 | // if no requested permission tier is matched, deny |
||
| 58 | throw UnauthorizedException::forPermissions($permissions); |
||
| 59 | } |
||
| 60 | } |
||
| 61 |