entrust icon indicating copy to clipboard operation
entrust copied to clipboard

Class name must be a valid object or a string

Open mvaliolahi opened this issue 8 years ago • 8 comments

i use below code for remove one record from roles table:

        if ( $role = Role::find($id)) {
            $role->delete();

            return response()->json(['status' => 'success', 'message' => 'operation was successful.']);
        }

but, an error happen and the message is:

Class name must be a valid object or a string

i google it!, for some answer i had to say config/entrust.php file exist.

mvaliolahi avatar Nov 16 '16 11:11 mvaliolahi

i solved this problem by use Role::whereId($id)->delete();

mvaliolahi avatar Nov 16 '16 13:11 mvaliolahi

I am currently experiencing the same problem. In the EntrustRoleTrait, there is a Config call like this: Config::get('auth.model') and the install documentation is not setting this parameter unless I don't understand it. So it's null. The documentation sets auth.providers.users.model setting . I dont think it's coincidence, now in the dev-master there is exactly Config::get('auth.providers.users.model')

I'll check to switch to dev-master.

flartet avatar Nov 16 '16 15:11 flartet

I'm rather new to Laravel and while trying to follow the instructions for setting up entrust, I cannot run the entrust:migration command without receiving this same error. Am I doing something wrong with the way I set up my config/auth.php perhaps?

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

Any help would be immensely appreciated!

rikdavis2023 avatar Dec 23 '16 18:12 rikdavis2023

@andrewelkins I also hit this Error. Please upload the new style in master.

Kras4ooo avatar Feb 20 '17 14:02 Kras4ooo

Add this method in Role model

dont forget to get Config Class: use Illuminate\Support\Facades\Config; public function users() { return $this->belongsToMany(Config::get('auth.providers.users.model'),Config::get('entrust.role_user_table'),Config::get('entrust.role_foreign_key'),Config::get('entrust.user_foreign_key'));

}

jameskandau avatar Jul 04 '17 06:07 jameskandau

god bless you man :)

mtanasiewicz avatar Jan 12 '18 16:01 mtanasiewicz

use this code YourModle::whereId($id)->delete();

anasmahjub1 avatar Oct 09 '18 19:10 anasmahjub1

Add this in your config/auth.php

'model' => \App\User::class,

jilenloa avatar Apr 06 '19 15:04 jilenloa