douhuifen9942 2019-02-14 07:08
浏览 66

将查询翻译成Laravel eloquent

I have a query:

public function upShops() {
DB:statement('update shops set position = 
(SELECT FIND_IN_SET( CONCAT(points, '_', created_at), 
(SELECT GROUP_CONCAT( CONCAT(points, '_', created_at) ORDER BY points desc, created_at desc ) FROM (select * from shops) as shop_rankings)))');
}

How I can this query translate to eloquent Laravel? I think that need do so:

Shop::update(['position' => '(SELECT FIND_IN_SET( CONCAT(points, '_', 
created_at), (SELECT GROUP_CONCAT( CONCAT(points, '_', created_at)'])-
>orderByDesc('points')->orderByDesc('created_at');

But this does not work. I get an error in the update method. How I can do eloquently correctly?

  • 写回答

2条回答 默认 最新

  • dth62818 2019-02-14 07:20
    关注

    Update eloquent method returns a boolean, true on success otherwise and error, and therefore you cannot chain methods like orderByDesc to it. An example of how to update would be something like:

    Shop::update(['position' => 'value']);
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!