I can see answers almost. But let me explain bit more.I can see that you are checking $datas
is empty or not. If you use helper function dd()
to dump $datas
values you can see that it always return a Collection from Illuminate\Support\Collection
. So even $datas
is empty it gives a empty Collection. You can test this by your self like below in your controller
if($datas) {
dd($datas);
}else{
dd('empty');
}
This will always show the empty Collection. So just using if
condition you cann't check a collection is empty. Instead of if
you can check a collection with below methods.
collect([])->isEmpty();
@if ($datas->isEmpty())
@endif
collect([])->isNotEmpty();
@if ($datas->isNotEmpty())
@endif
collect([])->first();
@if ($datas->first())
@endif
collect([])->count();
@if ($datas->count())
@endif
If you check Laravel Collection documentation you can find more.
Collections full documentation
Location above methods available
Edit 01
This answer directly answer your question. Please check
Eloquent Collection: Counting and Detect Empty