在 Laravel 5.6 中未找到特性“App\HasRoles”错误

reh*_*han 7 php permissions roles laravel

我尝试通过 laravel 5.6 角色权限系统

当我尝试使用默认身份验证(php artisan make:auth)注册时出现此错误

“Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN) Trait 'App\HasRoles' 未找到”

这是我的模型 user.php

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use Notifiable;
    use HasRoles;

    protected $guard_name = 'web'; 

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];
}
Run Code Online (Sandbox Code Playgroud)

Par*_*ras 4

我猜您正在使用 Spatie Laravel Permission 包。

如果是这样,您需要像这样导入该类:

use Spatie\Permission\Traits\HasRoles;