I am working in laravel 5.4 and trying to select few data from table and update a field of table. 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']);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.