-
-
Couldn't load subscription status.
- Fork 1.8k
Open
Description
Description
I wanted to get all users of a role (with the belongsToMany Relationship) and got an error stating Class name must be a valid object or a string. After a bit of debug, I noticed that $this inside the users() function was a completely new model (like when you call new Role()). However, before calling users(), I dumped $role and it was the correct Role with every attribute. By calling $role->users()->get(), all the users were displayed...
Steps To Reproduce
- add
Model::automaticallyEagerLoadRelationships();toAppServiceProvider.php - try to access
->usersnot the function; as a parameter - get
Class name must be a valid object or a string, because$this->existsisfalse,$this->guard_nameissanctum, because it's default, and is a new Role
Version of spatie/laravel-permission package:
6.21.0
Version of laravel/framework package:
v12.28.1
PHP version:
8.2.29
Database engine and version:
MariaDB 10.6.22
OS: Windows/Mac/Linux version:
linux
Metadata
Metadata
Assignees
Labels
No labels