12

I have followed zizac/entrust installation tutorial from GitHub Link and faced with 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

MigrationCommand.php file url : Link

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:publish was successful.

File : config/entrust.php exist.

I didin't change any options to config/auth.php file same as - auth.php. How to fix it?

Noproblem
  • 745
  • 1
  • 6
  • 15

4 Answers4

40

in vendor/zizaco/entrust/src/commands/MigrationCommand.php on line 86

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 :

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

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

then your problem will solve : happy coding

tapos ghosh
  • 2,114
  • 23
  • 37
  • This solve the problem. I'm on Laravel 5.2 and using multi auth. This works like charm! Thanks – Nizam Feb 02 '16 at 17:35
  • Many thanks for your answer. It is working fine with laravel 5.2..This should be marked as right answer..:-) – Vikas Sharma Feb 24 '16 at 18:31
  • @taposghosh, It gives the same error on role->delete() operation. Where else do I need change? – Aarohi Kulkarni May 19 '16 at 12:49
  • 3
    You should not edit direct vendor files as they will be overwritten in future updates. Instead you should add the correct lines to the config file until an update by Entrust updates their codebase to use the newer Laravel auth layout. – Brad Bird Aug 18 '16 at 11:47
  • you save me bro – Soul Coder Apr 11 '17 at 09:49
  • works in laravel 5.4.... following @BradBird. added in `code` config/auth.php`code` `code` /* * CONFIG FOR ENTRUST:MIGRATION * * */ 'table' => 'users', 'model' => App\Models\Usuario::class `code` – Cocuba May 19 '17 at 19:46
5

In vendor/zizaco/entrust/src/commands/MigrationCommand.php on line 86.

Laravel 5.1.* Add Line

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

Laravel 5.2.* Add Line

$usersTable  = Config::get('auth.providers.users.table');
$userModel   = Config::get('auth.providers.users.model');
Bono
  • 4,757
  • 6
  • 48
  • 77
  • 1
    While this code may answer the question, it would be better to include some context, explaining how it works and when to use it. Code-only answers are not useful in the long run. – Bono Apr 30 '16 at 14:25
3

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.

Add the following lines to config/auth.php underneath:

/*
|--------------------------------------------------------------------------
| 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',

Once Entrust rolls out an update you can remove this or keep it. Up to you.

Brad Bird
  • 737
  • 1
  • 11
  • 30
2

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.

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

and wait until Entrust will be upgraded to remove this

Marcin Nabiałek
  • 109,655
  • 42
  • 258
  • 291