1

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?

Munim Munna
  • 17,178
  • 6
  • 29
  • 58

3 Answers3

1

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!

Vadim Landa
  • 2,784
  • 5
  • 23
  • 33
0

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.

Jose Ayram
  • 198
  • 1
  • 14
0

@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);
   }
}
Sand Of Vega
  • 2,297
  • 16
  • 29