I'm currently working on a delete
function for my roles.
Every time when I try to delete:
Class name must be a valid object or a string
How do I fix this?
I'm currently working on a delete
function for my roles.
Every time when I try to delete:
Class name must be a valid object or a string
How do I fix this?
Add this function into Role.php model
<?php
namespace App;
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'));
}
}
Hope this helps!
Update the config/auth.php
file with 'model' => App\Users::class
, because vendor/zizaco/entrust/src/Entrust/Traits/EntrustRoleTrait.php
point to Config::get('auth.model')
in the $this->belongsToMany() method.
@Tiến Đạo says the best way to solve this problem. But If you want code simplicity....
use App\User;
class Role extends EntrustRole
{
/**
* Many-to-Many relations with the user model.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function users()
{
return $this->belongsToMany(User::class);
}
}