【问题标题】:How to perform an update containing a sub query on an Eloquent Relationship in laravel 5如何在 laravel 5 中对 Eloquent 关系执行包含子查询的更新
【发布时间】:2015-10-26 12:30:07
【问题描述】:

我是 laravel 的新手。我正在开发这个 laravel 5 应用程序,但在尝试执行如下查询时卡住了。

update applications 
set application_status = 'sa'
where id in (select application_id from application_cart where cart_id = 12);

感谢有关如何翻译此查询的帮助。

【问题讨论】:

    标签: mysql laravel laravel-5 eloquent


    【解决方案1】:

    下面的查询可以解决问题

    return Application::whereIn('id', function($query) use ($id){
                $query->from('application_cart')
                    ->select('application_id')->where('cart_id', $id);
            })->update(['application_status' => 'sa']);
    

    【讨论】:

      猜你喜欢
      • 2015-06-24
      • 2016-03-25
      • 2021-02-24
      • 2013-10-03
      • 2017-07-19
      • 2019-02-15
      • 1970-01-01
      • 1970-01-01
      • 2017-10-24
      相关资源
      最近更新 更多