美文网首页
Laravel 5.6 使用 Zizaco/Entrust 碰到

Laravel 5.6 使用 Zizaco/Entrust 碰到

作者: 用生命写Bug | 来源:发表于2018-05-08 14:27 被阅读0次

在按照 GitHub 文档中的步骤进行操作,执行到迁移数据的时候

php artisan entrust:migration

运行上面的命令,生成迁移文件,但是在 Laravel 5.6 版本中,执行这条命令报错:

Method Zizaco\Entrust\MigrationCommand::handle() does not exist

查看 vendor/zizaco/entrust/src/commands/MigrationCommand.php 文件,发现里面更笨没有 handle() 方法,经查找资料,发现是更名为 fire() 了,为了避免修改方法名导致一些没有必要的错误,所以我在 fire() 方法上面添加了另外一个方法:

public function handle()
{
  $this->fire();
}

接下来再执行生成迁移文件的命令,又抛出另外一个错误:

Symfony\Component\Debug\Exception\FatalThrowableError  : Class name must be a valid object or a string

...中间省略一部分错误提示...

  89|  $usersTable  = Config::get('auth.table');
  90|  $userModel   = Config::get('auth.model');
> 91|  $userKeyName = (new $userModel())->getKeyName();

检查发现,是因为无法获取到 tablemodel ,所以迁移文件无法正确生成。

打开 config/auth.php 文件,修改一下 providers 数组

'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
            'table' => 'users', //添加了table
        ],
    ],

然后回到 vendor/zizaco/entrust/src/commands/MigrationCommand.php 文件,修改成:

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

接下来再执行生成迁移文件命令,就可以正常执行了。

相关文章

网友评论

      本文标题:Laravel 5.6 使用 Zizaco/Entrust 碰到

      本文链接:https://www.haomeiwen.com/subject/cxbirftx.html