gpt4 book ai didi

php - 更新查询以更新 laravel 中的两个字段

转载 作者:行者123 更新时间:2023-11-29 01:20:16 26 4
gpt4 key购买 nike

我想更新 laravel 5.3 中的两个字段。我有两个字段值 'status_id' 和 'comment'。我的查询工作是我只更新 'status_id' 字段

  DB::table('travel_request')
->where('id',$id )
->update(['status_id' => DB::table('travel_request_status')->where('status', $status)->first()->id]);

我尝试按如下方式更新两个字段

DB::table('travel_request')
->where('id',$id )
->update(['status_id' => DB::table('travel_request_status')->where('status', $status)->first()->id],['comment'=>$comment]);

最佳答案

您要传递两个数组,但您应该传递一个数组,其中包含两个 key => value 对作为参数:

DB::table('travel_request')
->where('id', $id)
->update([
'status_id' => DB::table('travel_request_status')->where('status', $status)->first()->id,
'comment' => $comment
]);

关于php - 更新查询以更新 laravel 中的两个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39998456/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com