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

Don't reinvent features that Laravel already has

For example, soft deletes

Joel Clermont
Joel Clermont
2024-01-11

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

I see a lot of different Laravel projects, and one consistent problem I see is application code that could be better leveraging a built-in feature of Laravel.

For example, I recently did a code review on a project that had an archived_at column on a bunch of different tables. And then throughout controllers and model scopes, there was a lot of code to decide whether "archived" records should be returned.

This sounds suspiciously like soft deletes to me, which is already baked into Eloquent.

Sometimes Laravel will add a feature in a new version, and it may not make sense to immediately rewrite your code to use it, but soft deletes have been around almost since the beginning.

Lean into the framework and use what it offers. You'll write less code and other Laravel devs joining your team will be able to understand your code faster.

Here to help,

Joel

P.S. Want us to do a code review on your Laravel app? Check out our code review service.

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.