Reputation:
I fetching data from DB and passing to Google Map. But sometimes in address table, lat and lng rows are being empty. So if it happens and I use that half empty array Google Map is crushes. So when I fetching data in Controller is there any option like; if row empty go next row... For example:
public function index()
{
$Data = DB::table('allestates')->whereNotNull('lat')->whereNotNull('lng')->get();
return view('home', 'Data');
}
Of course this is not proper code but, I just want to show what I am trying. Is this possible?
Upvotes: 0
Views: 83
Reputation: 637
you can add check if a field is not null by using below code:
$Data = DB::table('allestates')
->whereNotNull('lat')
->whereNotNull('lng')
->get();
if (!empty($Data)){
}
Upvotes: 0
Reputation: 7333
You can use whereNotNull
:
public function index()
{
$Data = DB::table('allestates')->whereNotNull('lat')->whereNotNull('lng')->get();
if (!empty($Data)){
}
}
The filter you used (where('lat','lng')
) actually means "records where the field lat has the value 'lng'".
Upvotes: 1