In this episode, we look at some handy tweaks you might want to make to every new Laravel project you start. Laravel's default setup is great, but with a few opinionated changes, you can really boost your development experience. The episode is all about sharing four of these personal favorites.
Here's what we dive into:
Unguarding Models: We talk about the pros and cons of unguarded models. By default, Laravel protects your models from mass assignment vulnerabilities, but if you always diligently validate your data, you might want to globally unguard your models to save a ton of boilerplate. The episode demonstrates both the trade-offs and how to set this up safely in your AppServiceProvider
.
Strict Models: Next, we explore making your models strict. This increases safety by preventing things like lazy loading (which can cause sneaky N+1 query bugs), silently discarding attributes, and accessing missing attributes. These strict settings make debugging easier and help you catch mistakes early, especially in development. We see how to configure this globally and what kinds of errors to expect if you forget, say, to eager-load relationships.
Carbon Immutable: Date bugs can be the worst! By default, Carbon (Laravel’s date/time lib) is mutable, which can cause headaches if you accidentally change date objects. Here, we see how to swap to Carbon Immutable project-wide so you don't have to keep cloning your dates everywhere.
Prohibiting Destructive Production Commands: Nobody wants to accidentally nuke their production database. Laravel has some safeguards, but you can take it a step further and actually prohibit commands like migrate:reset
or db:wipe
from running in production at all. The episode shows you how to set this up so you can't accidentally drop your data, even if you’re in a rush (or a panic!).
Throughout, you'll get practical code samples, see what happens when you hit common pitfalls, and hear tips on customizing settings per environment. By the end, you'll have a toolkit of early-project tweaks to make your Laravel life safer and easier.