【问题标题】:entrust delete() error Class name must be a valid object or a stringentrust delete() 错误类名必须是有效的对象或字符串
【发布时间】:2016-11-16 12:00:09
【问题描述】:

我使用以下代码从角色表中删除一条记录:

if ( $role = Role::find($id)) {
    $role->delete();

    return response()->json(['status' => 'success', 'message' => 'operation was successful.']);
}

但是,发生错误,消息是:

类名必须是有效的对象或字符串

我用谷歌搜索!对于某些答案,我不得不说 config/entrust.php 文件存在。

【问题讨论】:

  • find() 方法有效,我可以看到结果。
  • 您确定这些行发出了消息吗?

标签: php entrust


【解决方案1】:

delete() 方法在角色模型上不起作用,在这种情况下删除一条记录或一个角色后 find for exp Role::whereId($id)->delete();为我工作,我的问题没有解决。

【讨论】:

    【解决方案2】:

    在角色模型中添加此方法:

    use Illuminate\Support\Facades\Config;
    
    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')
        );
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-17
      • 1970-01-01
      • 1970-01-01
      • 2023-01-13
      • 2018-04-23
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      相关资源
      最近更新 更多