I'm building an API to return shops from a database in ascending order except that it should begin with all shops named swiva eg Swiva Electronics, Swiva Gas, Swiva Mall etc. then proceed to all the other shops in ascending order. I have tried the following code
$shops=Shop::join('users','users.id','=','shops.owner_id')
->select('shops.id','shops.name','users.email','users.tel','users.estate','shops.logo')
->orderBy('shops.name')
->get()
->partition(function ($item) {
return $item->name != 'Swiva Electronics';
})->flatten();
but that is not doing what I want as
- It is not beginning with the intended row rather it is ending with it.
- It is only working with one row only, I do not know how to specify all the other rows
Note that the output of this query is being returned as a json as follows
if(!$shops->isEmpty()){
return response()->json([
'success'=>true,
'shops'=> $shops
]);
}else if($shops->isEmpty()){
return response()->json([
'success'=>false,
'message'=> 'There exists no subscribed shops from '
]);
}
How can I achieve the intended output either through formatting the JSON( Which I do not know how to do) or by using eloquent functions.