-
|
I extended the User class for a role. (Example) I gave Student a global scope for the 'student' role. This way, rather than call The global scope works just fine with Eloquent conditions (ie. where clause, etc), but the second I use the spatie role methods i always get back an empty collection. Any ideas why this is not working? Tried it with both class Student extends User
{
/**
* The "booted" method of the model.
*
* @return void
*/
protected static function booted()
{
parent::booted();
static::addGlobalScope('foobar', function (Builder $builder) {
$builder->role('student'); // always an empty collection
});
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
Given that I don't currently have an app set up that would let me step through the code to figure out what might be contributing to the matter, I offer the following which is where I'd start exploring in such an app:
Hope that helps! |
Beta Was this translation helpful? Give feedback.
Given that I don't currently have an app set up that would let me step through the code to figure out what might be contributing to the matter, I offer the following which is where I'd start exploring in such an app:
scopeRole()method on the trait is actually being called, or if something else is being triggered. Maybe add add()in there?dd()the$builderto check whether there's a mismatch of objects used vs expectedscopeRole()method into youraddGlobalScope(), but using only as little as possible. Perhaps start with just its return closure, after reducing the$rolesvariable value to just the object it rep…