| Conditions | 7 |
| Paths | 17 |
| Total Lines | 34 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 8.5432 |
| Changes | 7 | ||
| Bugs | 0 | Features | 2 |
| 1 | <?php |
||
| 56 | 1 | public function handle(Request $request, Closure $next, $roles) |
|
| 57 | { |
||
| 58 | 1 | $accessDenied = true; |
|
| 59 | |||
| 60 | 1 | if (!$user = $this->auth->getActiveUser()) { |
|
| 61 | Flash::error(trans('dashboard::dashboard.flash.access_denied')); |
||
| 62 | |||
| 63 | return redirect()->route('auth.login'); |
||
| 64 | } |
||
| 65 | |||
| 66 | 1 | if (!is_array($roles)) { |
|
| 67 | 1 | $roles = [$roles]; |
|
| 68 | 1 | } |
|
| 69 | |||
| 70 | 1 | foreach ($roles as $role) { |
|
| 71 | |||
| 72 | 1 | if (!$role = $this->role->getBySlug($role)) { |
|
| 73 | continue; |
||
| 74 | } |
||
| 75 | |||
| 76 | 1 | if ($user->inRole($role)) { |
|
| 77 | $accessDenied = false; |
||
| 78 | } |
||
| 79 | 1 | } |
|
| 80 | |||
| 81 | 1 | if ($accessDenied) { |
|
| 82 | 1 | Flash::error(trans('dashboard::dashboard.flash.access_denied')); |
|
| 83 | |||
| 84 | // Redirect back to the previous page where request was made. |
||
| 85 | 1 | return redirect()->back(); |
|
| 86 | } |
||
| 87 | |||
| 88 | return $next($request); |
||
| 89 | } |
||
| 90 | } |