[英]How can we select and update a table in laravel 5.4 using eloquent?
I am working in laravel 5.4 and trying to select few data from table and update a field of table. 我在laravel 5.4中工作,尝试从表中选择一些数据并更新表的字段。 I followed below script.
我遵循以下脚本。 I am not sure Is this correct method or not.
我不确定这是否是正确的方法。 Please correct me.
请纠正我。
$bookings = Booking::where('is_delete', 0)
->where('status', '1')
->where('payment_status', '1')
->get();
foreach($bookings as $booking) {
$booking->status = '3';
$booking->save();
}
Try This 尝试这个
$bookings = Booking::where('is_delete', 0)
->where('status', '1')
->where('payment_status', '1')
->get();
foreach($bookings as $booking)
{
Booking::where('id',$booking->id)->update(['status'=>'3']);
}
您可以像这样简单地更新
Booking::where('is_delete', 0)->where('status', '1')->where('payment_status', '1')->update(['status'=>'3']);
更简单的更新编码...
Booking::where([['is_delete', '=', 0], ['status', '=', '1'], ['payment_status', '=', '1']])->update(['status' => '3']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.