Add a global scope: https://laravel.com/docs/9.x/eloquent#global-scopes
Nov 22, 2022
2
Level 3
Is there a way to add a where clause the query everytime it's called?
I have city_id in my users table. And every user has more than one product. Is there a way to automatically add whereCityId(Auth::user()->city_id) to all my queries?
I know I can make a hasone method in the model but I want it to be included as soon as I make a query for it.
In simpler words, I want to get Model::whereCityId(Auth::user()->city_id)->get() when I type Model::all()
Level 102
1 like
Please or to participate in this conversation.