除了某些特定行以外
我正在建立一个API,以升级顺序从数据库返回商店,除非它应该从所有名为Swiva的商店开始,例如Swiva Electronics,Swiva Gas,Swiva Mall等。 我已经尝试了以下代码
$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();
,但这并不是我想要的,因为
- 它不是从预期的行开始的,而是以此为止。
- 它仅与一行一起工作,我不知道如何指定所有其他行
请注意,此查询的输出作为JSON返回,如下所示,
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 '
]);
}
我该如何通过格式化JSON来实现预期的输出(我不知道该怎么做)或使用雄辩的功能。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用MySQL的现场函数来实现此目的,请参见:
由于我们无法在字段选项中添加所有名称,默认情况下它将列出所有其他名称首先使用desc desc and deSc andver invert invert invert invert invert invert unvert unvert it inver it unvert unvert unvert unvert unvert unvert it in actuct in Resulte首先移动这些名称通过按商店名称添加简单的ASC订单来名称。
You can use the Field Function of MySQL to achieve this see: https://www.w3schools.com/sql/func_mysql_field.asp
As we can't add all names in FIELD options by default it will list all other names first Use DESC order to invert it will move those names first in results and then sort the all other shop names by adding simple ASC order by shop names.