簡體   English   中英

我們如何使用雄辯的方式在laravel 5.4中選擇和更新表?

[英]How can we select and update a table in laravel 5.4 using eloquent?

我在laravel 5.4中工作,嘗試從表中選擇一些數據並更新表的字段。 我遵循以下腳本。 我不確定這是否是正確的方法。 請糾正我。

$bookings   = Booking::where('is_delete', 0)
            ->where('status', '1')
            ->where('payment_status', '1')
            ->get();

foreach($bookings as $booking) {
    $booking->status = '3';
    $booking->save();
}

嘗試這個

$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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM