Using a Trait to apply a global scope

Posted 4 months 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?


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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.