【问题标题】:issue in deleting role in Zizaco/entrust在 Zizaco/entrust 中删除角色的问题
【发布时间】:2016-06-20 08:14:54
【问题描述】:

我正在尝试删除角色

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

我收到以下错误

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

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

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

榜样课

namespace App\Models;

use Zizaco\Entrust\EntrustRole;

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

}

【问题讨论】:

  • 可以发一下Role类的内容吗?
  • 我在回答对话框中发布了它
  • 好的,但是最好编辑原始帖子/问题并将其添加到那里 - 这样其他人也可以看到它 - 也许他们有一个想法。
  • 并且:如果这最终是您的问题,请查看此问题。 github.com/Zizaco/entrust/issues/500
  • 不,它没有帮助

标签: laravel entrust


【解决方案1】:

我认为这是问题所在:

查找文件: 供应商/zizaco/entrust/src/Entrust/Traits/EntrustRoleTrait.php

替换

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

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

【讨论】:

  • 核心包不得改动。您的更改可能会在您下次更新时替换。
【解决方案2】:

更新核心包中的任何内容都不是一个好习惯,因为如果您更新包,此更改将被替换,而是通过在您的 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'));
}

【讨论】:

    【解决方案3】:

    我同意@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);
    }
    

    【讨论】:

      猜你喜欢
      • 2019-10-14
      • 2018-02-12
      • 2017-02-05
      • 2016-07-28
      • 1970-01-01
      • 2015-04-03
      • 1970-01-01
      • 1970-01-01
      • 2018-07-06
      相关资源
      最近更新 更多