0
votes

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:

enter image description here

2
please share your User modelOMR

2 Answers

0
votes

You forgot to include the roles trait

use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;

class User extends Authenticatable
{
    use HasRoles; //this line

    // ...
}
0
votes

Make sure your User model uses the Spatie\Permission\Traits\HasRoles trait.

<?php

use Spatie\Permission\Traits\HasRoles;

class User
{
    use HasRoles;
}