I have checked this, this links for the solution but cannot find the suitable one for me.
I am trying to retrieve the records which have exact matches first and then related matches.
Here is what I have tried so far.
$facility = DB::table('facility')
->select('ID', 'Name', 'Address', 'Phone', 'Latitude', 'Longitude')
->where('Name', 'like', $q . '%')
->where('Name', '!=', '')
->limit(10)
->get();
if(empty($facility)) {
$facility1 = DB::table('facility')
->select('ID', 'Name', 'Address', 'Phone', 'Latitude', 'Longitude')
->where('Name', 'like', '%' . $q . '%')
->where('Name', '!=', '')
->limit(10)
->get();
}
$facility->{'facility1'} = $facility1;
I have tried to merge this 2 objects. But I'm not getting the desired output.
Is there any way to get output with just one query?
EDIT: i.e. I just want to retrieve the records with exact match first and then other records. Like If I search for "OOS" then the First record should be "OOS Healthcare" and then "Fat loss" likewise.