do not apply global scope in filament admin (app)

I have a global scope on my User model that is extremely important for 99% of my app that lives outside of the filament admin. I only allow certain users within the admin area. I do want the scope still applied to those same users outside of the admin. With that said, any suggestions for knowing I am within the admin (any resource/page, etc) with filament admin so that i can exclude using that scope during that time? Looking for something rock solid and reliable.
19 Replies
Dennis Koch
Dennis Kochβ€’2y ago
You could remove it inside Filament::serving()
Mark Chaney
Mark ChaneyOPβ€’2y ago
Any ideas on how to actually unset the globalscope? All docs ive seen are removing it for a query, etc.
Dennis Koch
Dennis Kochβ€’2y ago
Um, good question πŸ˜…
Mark Chaney
Mark ChaneyOPβ€’2y ago
maybe there is a way to not apply it in the first place by identifying in the scope methods apply() if its being called within filament in the first place? im just nots sure of the reliable way to do that. sure there are some hackish methods, but id rather avoid those and do it right
Dennis Koch
Dennis Kochβ€’2y ago
You'd need to apply it in a middleware then
Mark Chaney
Mark ChaneyOPβ€’2y ago
i mean, the middleware is the same between the two
Dennis Koch
Dennis Kochβ€’2y ago
Yeah, I don't see another way. The array is protected and there is no method to remove it again
Mark Chaney
Mark ChaneyOPβ€’2y ago
I will see if any of the laravel crew in their discord have any ideas or maybe dan will have some ideas if he sees this. I will avoid tagging him though. πŸ˜›
Dennis Koch
Dennis Kochβ€’2y ago
You could suggest PRing it to Laravel πŸ˜…
Mark Chaney
Mark ChaneyOPβ€’2y ago
ok, 2:15am. will pickup it up in the morning. lol well my attempt at getting ideas in the laravel discord failed miserably. They more just wanted to point out its obviously not global then....
Dan Harrin
Dan Harrinβ€’2y ago
Laravel - The PHP Framework For Web Artisans
Laravel is a PHP web application framework with expressive, elegant syntax. We’ve already laid the foundation β€” freeing you to create without sweating the small things.
Dan Harrin
Dan Harrinβ€’2y ago
did you not read this far in the docs? πŸ˜‰
Mark Chaney
Mark ChaneyOPβ€’2y ago
@Dan Harrin huh? thats per query
Dennis Koch
Dennis Kochβ€’2y ago
Did you not read this far in this thread? 😜 πŸ˜…
Dan Harrin
Dan Harrinβ€’2y ago
yeah in getEloquentQuery() ?
Dennis Koch
Dennis Kochβ€’2y ago
But yeah. Why do you even need to remove it for every request inside the admin panel? πŸ˜…
Dan Harrin
Dan Harrinβ€’2y ago
OR you could apply the global scope in middleware, and only apply it to the non-admin routes
Dennis Koch
Dennis Kochβ€’2y ago
That's what we figured so far.
Mark Chaney
Mark ChaneyOPβ€’2y ago
hmm, though I have a bigger problem anyway as im finding that the when using the impersonate package, its not properly setting the tenant id, so i need to figure that out. thats the biggest use case of filament for this project, that and just basic user management so i need to see how that is being set and how that would work with transition between the admin portal and client portal. fun stuff i tell you. lol
Want results from more Discord servers?
Add your server