Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| RootOnly | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 1 |
| handle | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Middleware; |
| 4 | |
| 5 | use Closure; |
| 6 | use Illuminate\Http\Request; |
| 7 | use Illuminate\Support\Facades\Auth; |
| 8 | |
| 9 | class RootOnly |
| 10 | { |
| 11 | /** |
| 12 | * Fail with HTTP 403 if the user is not role_id 1 (root) |
| 13 | * |
| 14 | * Note that we override how this error is returned and displayed |
| 15 | * |
| 16 | * @param \Illuminate\Http\Request $request |
| 17 | * @param \Closure $next |
| 18 | * @return mixed |
| 19 | * |
| 20 | * @see App\Exceptions\Handler\render |
| 21 | */ |
| 22 | public function handle(Request $request, Closure $next) |
| 23 | { |
| 24 | if (Auth::user()->role->id != 1) { |
| 25 | abort(403, 'rootonly'); |
| 26 | } |
| 27 | return $next($request); |
| 28 | } |
| 29 | } |