russellwwest
1 year ago
331
3
Laravel

Using a Trait to apply a global scope

Posted 1 year ago by russellwwest

Currently I have a global scope that filters models by the logged in user’s account_id. I have used an interface to make sure I implement the boot method on the models I need it on. This works perfectly fine, but is quite repetitive.

So I’d like to know how to implement this global scope through a trait, just like laravel’s own soft deletes trait.

Any tips or helpers in the right direction would be much appreciated?

Thanks

Please sign in or create an account to participate in this conversation.