Skip to content

Added a global scope to User model, role method always returns empty collection #1731

Answered by drbyte
cjaoude asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  • I'd check whether the scopeRole() method on the trait is actually being called, or if something else is being triggered. Maybe add a dd() in there?
  • in your closure maybe dd() the $builder to check whether there's a mismatch of objects used vs expected
  • consider cloning a bunch of the scopeRole() method into your addGlobalScope(), but using only as little as possible. Perhaps start with just its return closure, after reducing the $roles variable value to just the object it rep…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@cjaoude
Comment options

@cjaoude
Comment options

Answer selected by drbyte
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
2 participants