我知道这已经是一个被过度讨论的问题,但我相信我并没有犯通常犯的错误。使用 Laravel 的 Entrust 包创建角色和权限时出现此错误。我正在尝试将权限附加到角色(注意,不是直接附加到模型)并收到此错误。这是一些代码:
use Illuminate\Database\Seeder;
use App\Role;
use App\Permission;
class RolePermissionSeeder extends Seeder
{
//assign permissions to roles
public function run()
{
//assign permissions to admin
$admin = Role::where('name', 'admin');
$assignTrainerRole = Permission::where('name', 'assign-trainer-role');
$removeTrainerRole = Permission::where('name', 'remove-trainer-role');
$assignTraineeRole = Permission::where('name', 'assign-trainee-role');
$removeTraineeRole = Permission::where('name', 'remove-trainee-role');
$attachToTrainer = Permission::where('name', 'attach-to-trainer');
$detachFromTrainer = Permission::where('name', 'detach-from-trainer');
$admin->attachPermissions(
[
$assignTrainerRole,
$removeTrainerRole,
$assignTraineeRole,
$removeTraineeRole,
$attachToTrainer,
$detachFromTrainer,
]
);
// snipped
现在,根据我的发现,当人们尝试直接在用户或其他模型上设置权限时,通常会出现此错误。但我不这样做。我正在尝试为角色分配权限,但仍然出现此错误。有人可以帮忙吗?