Black Friday: the Laravel testing course is $149 instead of $249, through Dec 7. See the course →
logo

Clean up unused policy methods

Don't make a future developer guess

Joel Clermont
Joel Clermont
2025-03-03

From our daily Laravel tips email. Get the next one in your inbox.

When you use artisan to make a new policy, and you provide it with a model, it will stub out all 7 resourceful policy methods for you.

It will always include methods like restore and forceDelete for you, even if your model doesn't use the SoftDeletes trait.

I would recommend deleting those methods if they don't apply to your model. It's just noise.

But I'd go a step further, and make the same recommendation to delete other policy methods you don't plan on using.

By default, an empty policy method is evaluated as an authorization failure, so you aren't accidentally opening a security hole by deleting it and then checking it.

In the future, if you build a feature that needs one of those methods, add it at that point, but don't leave a bunch of empty methods around. The next developer that looks at the file (or even you in the future), won't know if it was left empty on purpose, or if it was a mistake.

If you really want to keep the method there, at least make it explicitly return false to avoid confusion.

Here to help,

Joel

P.S. If you'd like development help from two devs that really care about writing maintainable Laravel apps, we would love to talk.

Want a tip like this in your inbox every weekday?

Each one takes less than 2 minutes to read. Join 4,000+ Laravel developers who already get them.

email
No spam. Only real-world advice.
Toss a coin in the jar if you found this helpful.