Role relationship uses the wrong model_type in spatie/laravel

28 Views Asked by At

I tried to list roles and check if a user has a particular role. The model type stored in table model_has_roles is Modules\Admin\Entities\User instead of the default App\Models\User. I use users relationship provided by spatie role. So here is the query in my controller:

$roles = Role::withCount([
               'users' => function ($query) use ($id){
                    return $query->where('model_id', $id)->limit(1);
                }
         ])
         ->orderBy('name')
         ->get();

As the result, the users_count always return 0 because the model_type is App\Models\User instead of Modules\Admin\Entities\User. How can I change the model_type to the one that should be? I was thinking that I need to extend the Role model but I don't know how to do it.

0

There are 0 best solutions below