Currently I am to do Model::where('status', 1) to filter off inactive models before adding any other subqueries to it. I find myself doing this all the time and Its quite stressful as sometimes I could forget to add that part. I wish to have something that will automatically add the where clause anytime I run a query on the model. Something that works like the typical Laravel SoftDeletes that adds the WHERE deleted_at IS NULL clause automatically to all queries.
Example:
Instead of writing Model::where('status', 1)->first(), I could just write Model::first() and this will be automatically transformed to Model::where('status', 1)->first().
How do I achieve this please ?
What you're looking are the Query Scopes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With