I'm using Laravel-Permissions and wrote in rotes\web.php:
Route::group(['middleware' => ['role:admin']], function () {
Route::get('/admin', function () {
return "Test";
});
});
I added in app\Http\Kernel.php :
protected $routeMiddleware = [
// ...
'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
];
Error:
My Answer:
> Route::group(['middleware' => ['auth']], function () {
> Route::get('/dashboard', 'DashboardController@index')->name('dashboard');
> Route::get('/admin', 'AdminController@index')->name('admin')->middleware('role:admin');
> });
Rate this post
5 of 5 based on 2338 votesComments