如何修复 laravel 5.2 zizaco entrust:migration class 名称验证?

How to fix in laravel 5.2 zizaco entrust:migration class name validation?

我已按照 GitHub Link 中的 zizac/entrust 安装教程进行操作,但遇到错误:

Class name must be a valid object or a string in var/www/html/laravel_test/vendor/zizaco/entrust/src/commands/MigrationCommand.php on line 86

MigrationCommand.php 文件 url : Link

输出:

php artisan entrust:migration

Tables: roles, role_user, permissions, permission_role
A migration that creates 'roles', 'role_user', 'permissions', 'permission_role' tables will be created in database/migrations directory

Proceed with the migration creation? [Yes|no] (yes/no) [yes]: yes

Creating migration...
PHP Fatal error:  Class name must be a valid object or a string in /var/www/html/laravel_test/vendor/zizaco/entrust/src/commands/MigrationCommand.php on line 86

命令:php artisan vendor:publish 成功。

文件:config/entrust。php 存在。

我没有更改 config/auth.php 文件的任何选项,与 - auth.php 相同。如何解决?

尝试 运行:

php artisan config:cache

确保您的应用程序使用新的配置文件

编辑

好的,现在我明白了,这个库想用:

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

但是 auth 中没有这样的东西了。

因此,作为临时解决方法,您应该像这样将 tablemodel 添加到 auth 文件中:https://github.com/laravel/laravel/blob/5.1/config/auth.php

等到 Entrust 升级后删除这个

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

删除行:

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

添加行:

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

和 config/auth.php 文件写入提供商行,就像我一样:

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

    // 'users' => [
    //     'driver' => 'database',
    //     'table' => 'users',
    // ],
],

那么你的问题就会解决:编码愉快

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

Laravel 5.1.* 添加行

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

Laravel 5.2.* 添加行

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

接受的答案可能会解决问题,但编辑直接供应商文件是非常糟糕的做法。以下内容将解决您可能遇到的问题,如果您决定更新 Entrust 并且他们修复了他们的代码库,将支持您的应用程序继续运行。

将以下行添加到 config/auth.php 下面:

/*
|--------------------------------------------------------------------------
| User Providers
|--------------------------------------------------------------------------
|
| All authentication drivers have a user provider. This defines how the
| users are actually retrieved out of your database or other storage
| mechanisms used by this application to persist your user's data.
|
| If you have multiple user tables or models you may configure multiple
| sources which represent each model / table. These sources may then
| be assigned to any extra authentication guards you have defined.
|
| Supported: "database", "eloquent"
|
*/

Laravel 5.1 - 5.4

'model' => \App\Models\User::class,
'table' => 'users',

一旦 Entrust 推出更新,您可以删除或保留它。由你决定。