mercredi 7 octobre 2020

how to update previous record of db table on basis of current record?

i want to update previous record of db table using some conditions there is $order is a last record of db
and $old_order[1] is 2nd last order it should update previous order data but it only delete order not update previous order here is code

if( $order->ot_customer_distance * 1000 < 200 )
                 $old_order = Order::where('customer_id' , $order->customer_id)->orderBy('id' , 'desc')->get();
                 $chk_ord = $old_order[1]->chk_ord_vst;
                 $old_order_id = $old_order[1]->id;
                
                 if($chk_ord >= 4){
                  $setorder = 2;
                 }
                 elseif($chk_ord == 3){
                  $setorder = 2;
                 }
                 elseif($chk_ord == 2){
                  $setorder = 1;
                 }
                 elseif($chk_ord <= 1){
                  $setorder = 0;
                 }   
                 $succ = Order::where('id', $old_order_id)->update(['chk_ord_vst'=> $setorder]);
                 $this->deleteorder($order->id);
             }


from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2Swht4W
via IFTTT

Aucun commentaire:

Enregistrer un commentaire