I am accessing my database using model by using following code.
$persons = WysPerson::where('family_id', $id)->get();
I checked $persons
is empty or not by using following code.
if($persons){
var_dump($persons);
}
Actually $persons
is empty. But I am getting result for var_dump
as
object(Illuminate\Database\Eloquent\Collection)#417 (1) { ["items":protected]=> array(0) { } }
How will I check $persons
is empty? Can anyone help?
Using empty() won't work as usual when using it on an object, because the __isset() overloading method will be called instead, if declared. Therefore you can use count() (if the object is Countable). Or by using get_object_vars() , e.g.
You can use the isEmpty method:
http://laravel.com/api/5.0/Illuminate/Support/Collection.html#method_isEmpty
Use the count function
@if (count($persons))
If you have eloquent collection, call the function isEmpty()
like this:
$persons->isEmpty();
This return true or false. Hope this helps.
try this.
is_null($var)?abort('empty'):abort('filled')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With