XorY methods
XorY methods
Eloquent has quite a few functions that combine two methods, like “please do X, otherwise do Y”.

findOrFail()

Eloquent has quite a few functions that combine two methods, like “please do X, otherwise do Y”.

Instead of:

$user = User::find($id);if (!$user) { abort (404); }

Do this:

$user = User::findOrFail($id);

What's your reaction?

Comments

https://www.magazine.tdbcomputing.com/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!

Facebook Conversations

Disqus Conversations