如何在 laravel 5.2 zizaco entrust:migration 类名验证中修复?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34529621/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to fix in laravel 5.2 zizaco entrust:migration class name validation?
提问by Noproblem
I have followed zizac/entrust installation tutorial from GitHub Linkand faced with error:
我已经按照 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
类名必须是第 86 行 var/www/html/laravel_test/vendor/zizaco/entrust/src/commands/MigrationCommand.php 中的有效对象或字符串
MigrationCommand.php file url : Link
MigrationCommand.php 文件网址:链接
Outut:
输出:
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
the command: php artisan vendor:publishwas successful.
命令:php artisan vendor:publish成功。
File : config/entrust.php exist.
文件:config/entrust.php 存在。
I didin't change any options to config/auth.php file same as - auth.php. How to fix it?
我没有更改 config/auth.php 文件的任何选项,与 - auth.php相同。如何解决?
回答by tapos ghosh
in vendor/zizaco/entrust/src/commands/MigrationCommand.php on line 86
在第 86 行的 vendor/zizaco/entrust/src/commands/MigrationCommand.php 中
remove line :
删除行:
$usersTable = Config::get('auth.table');
$userModel = Config::get('auth.model');
add line :
添加行:
$usersTable = Config::get('auth.providers.users.table');
$userModel = Config::get('auth.providers.users.model');
and config/auth.php file write provider line as like me :
和 config/auth.php 文件像我一样写提供者行:
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
'table' => 'users',
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
then your problem will solve : happy coding
那么你的问题就会解决:快乐编码
回答by sebahattin ?atal
In vendor/zizaco/entrust/src/commands/MigrationCommand.php on line 86.
在第 86 行的 vendor/zizaco/entrust/src/commands/MigrationCommand.php 中。
Laravel 5.1.* Add Line
Laravel 5.1.* 添加行
$usersTable = Config::get('auth.table');
$userModel = Config::get('auth.model');
Laravel 5.2.* Add Line
Laravel 5.2.* 添加行
$usersTable = Config::get('auth.providers.users.table');
$userModel = Config::get('auth.providers.users.model');
回答by Brad Bird
The accepted answer may fix the problem but it is very bad practice to edit direct vendor files. The following will fix the issue you may be having and will support your app still working if you decide to update Entrust and they fix their codebase.
接受的答案可能会解决问题,但编辑直接供应商文件是非常糟糕的做法。如果您决定更新 Entrust 并且他们修复了他们的代码库,以下内容将解决您可能遇到的问题,并支持您的应用程序仍然有效。
Add the following lines to config/auth.phpunderneath:
将以下行添加到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
Laravel 5.1 - 5.4
'model' => \App\Models\User::class,
'table' => 'users',
Once Entrust rolls out an update you can remove this or keep it. Up to you.
一旦 Entrust 推出更新,您可以删除或保留它。由你决定。
回答by Marcin Nabia?ek
Try running:
尝试运行:
php artisan config:cache
to make sure your application is using fresh config files
确保您的应用程序使用新的配置文件
EDIT
编辑
Ok, now I see, this library want to use:
好的,现在我明白了,这个库想要使用:
$usersTable = Config::get('auth.table');
$userModel = Config::get('auth.model');
but there is no something like this in auth
any more.
但再也没有这样的东西auth
了。
So as temporary workaround you should probaby add table
and model
to auth
file like so: https://github.com/laravel/laravel/blob/5.1/config/auth.php
因此,作为临时解决方法,你应该probaby增加table
和model
对auth
文件像这样:https://github.com/laravel/laravel/blob/5.1/config/auth.php
and wait until Entrust will be upgraded to remove this
并等到 Entrust 升级以删除此