Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

I would say: if( $sale )

Or being pessimist: if( !$sale ) throw new Exception('Alias ' . $alias ' . does not exist');

But i'm all ears to alternative ways!

Last updated 2 years ago.
0

What about firstOrFail() and then handle ModelNotFoundException?

Last updated 2 years ago.
0

I have found two ways to do that :

if($sale->isEmpty()) : but only available for a get() and not for a first()

and

count($sale) : if > 0, $sale contains a result

Last updated 2 years ago.
0
$user = whatever;
if ( ! $user) {
    bail here
}
Last updated 2 years ago.
0

Please, at least use isset() !

Last updated 2 years ago.
0

use isset(). worked.

دریل شارژی

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

soclosed soclosed Joined 5 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.