Source: sebastiandedeyne.com

Eloquent findOrFail caveats

Category: Laravel

We think you might be interested in this job:

I use Model::findOrFail a lot in Laravel. Recently, I realized it’s not always the best option.

$title = Post::findOrFail($id)->title; Another benefit is that Laravel returns a 404 response for you when the model doesn’t exist. It’s a great feature in controllers and other outer layers of your application, but can be harmful in core business logic.

In addition, Laravel doesn’t report model not found exceptions to error trackers.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Community Partners