删除 Zizaco/entrust 中的角色时出现问题

issue in deleting role in Zizaco/entrust

我正在尝试删除一个角色

$role = Role::findOrFail(1);
$role->delete();

我收到以下错误

FatalErrorException in Model.php line 945:
Class name must be a valid object or a string

在 vendor/zizaco/entrust/src/commands/MigrationCommand.php 第 86 行

$usersTable  = Config::get('auth.providers.users.table');
$userModel   = Config::get('auth.providers.users.model');

榜样class

namespace App\Models;

use Zizaco\Entrust\EntrustRole;

class Role extends EntrustRole
{
       protected $fillable =  ['name', 'display_name', 'isActive','description', 'created_at', 'updated_at'];

}

我认为这是问题所在:

查找文件: vendor/zizaco/entrust/src/Entrust/Traits/EntrustRoleTrait.php

替换

第 51 行: ... Config::get('auth.model') ...

第 51 行: ... Config::get('auth.providers.users.model') ...

更新核心包中的任何内容都不是好习惯,因为如果您更新包,此更改将被替换,而不是通过在您的 App\Role.php

中添加它来覆盖该功能
/**
 * Many-to-Many relations with the user model.
 *
 * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
 */
public function users()
{
    return $this->belongsToMany(Config::get('auth.providers.users.model'), Config::get('entrust.role_user_table'),Config::get('entrust.role_foreign_key'),Config::get('entrust.user_foreign_key'));
   // return $this->belongsToMany(Config::get('auth.model'), Config::get('entrust.role_user_table'));
}

我同意@Tarunn。如果你想要代码简单....

use App\User;

/**
* Many-to-Many relations with the user model.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/

public function users()
{
   return $this->belongsToMany(User::class);
}