【问题标题】:How to fix in laravel 5.2 zizaco entrust:migration class name validation?如何修复 laravel 5.2 zizaco 委托:迁移类名验证?
【发布时间】:2016-04-04 10:24:35
【问题描述】:

我遵循了来自 GitHub Link 的 zizac/entrust 安装教程,但遇到了错误:

类名必须是有效的对象或字符串 var/www/html/laravel_test/vendor/zizaco/entrust/src/commands/MigrationCommand.php 在第 86 行

MigrationCommand.php 文件地址: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 laravel laravel-5 laravel-artisan entrust


    【解决方案1】:

    接受的答案可能会解决问题,但编辑直接供应商文件是非常糟糕的做法。如果您决定更新 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 推出更新,您可以删除或保留它。由你决定。

    【讨论】:

      【解决方案2】:

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

      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');
      

      【讨论】:

      • 虽然这段代码可以回答这个问题,但最好包含一些上下文,解释它是如何工作的以及何时使用它。从长远来看,纯代码的答案没有用处。
      【解决方案3】:

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

      删除线:

          $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',
          // ],
      ],
      

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

      【讨论】:

      • 这样就解决了问题。我在 Laravel 5.2 上并使用多重身份验证。这就像魅力!谢谢
      • 非常感谢您的回答。它在 laravel 5.2 上运行良好..这应该被标记为正确答案..:-)
      • @taposghosh,它在 role->delete() 操作上给出了相同的错误。我还有什么地方需要改变?
      • 您不应编辑直接供应商文件,因为它们将在未来的更新中被覆盖。相反,您应该在配置文件中添加正确的行,直到 Entrust 更新其代码库以使用更新的 Laravel auth 布局。
      • 你救了我兄弟
      【解决方案4】:

      尝试运行:

      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 升级后将其删除

      【讨论】:

      • 谢谢,还是同样的问题。我认为问题出在 config/auth.php 文件上。
      • 您能出示您的User.php 文件吗?它应该在App 命名空间中
      猜你喜欢
      • 1970-01-01
      • 2016-12-04
      • 1970-01-01
      • 2016-06-06
      • 1970-01-01
      • 2018-02-20
      • 2015-10-10
      • 1970-01-01
      • 2018-08-01
      相关资源
      最近更新 更多