我想减少产品数量后,一个订单交付拉维7

lhcgjxsq  于 2021-08-09  发布在  Java
关注(0)|答案(1)|浏览(337)

这是我确认订单已送达的按钮

@elseif($order->order_status == 'Confirmed')
        <div >
          <form enctype="multipart/form-data" action="{{route('updateorderstatus',['order'=>$order->id])}}" method="post" >
           @csrf
<input  name="order_id" type="hidden" value="{{$order->id}}"/>
          <input name="order_status" type="hidden" value="Shipping"/>
              <a data-toggle="tooltip" data-placement="top" title="">
        <button  type="submit" class="btn btn-link">
        <i class="fa fa-plane" aria-hidden="true"></i>

        </button>
       </a>
     </form>
     </div>
@elseif( $order->order_status == 'Shipping'  )
                                    <div   class="btn-group" role="group" aria-label="Third group">
                                        <form enctype="multipart/form-data" action="{{route('updateorderstatus')}}" method="post" >
                                            @csrf
                                            <input  name="order_id" type="hidden" value="{{$order->id}}"/>
                                            <input name="order_status" type="hidden" value="Delivered"/>
                                            <input  name="quantity" type="hidden" value="{{$order->quantity}}"/>
                                            <input  name="product_id" type="hidden" value="{{$order->product_id}}"/>
                                            <a data-toggle="tooltip" data-placement="top" title="">
                                                <button  type="submit" class="btn btn-link">
                                                    <i class="fa fa-check-square-o" aria-hidden="true"></i>
                                                </button>
                                            </a>
                                        </form>
                                    </div>

更新订单状态和我尝试减少数量的功能

public function updateorderstatus(Request $request)

{
    $order = Order::all();
    if ($request->isMethod('post')  ){

            $data = $request->all();

            Order::where('id',$data['order_id'])->update(['order_status'=>$data['order_status']]);

             $current = Order::where('order_status','Delivered')->get();

              Dvproduct::where('product_id',$data['product_id'])->update( ['quantity'=>$current - $data['quantity']] );

    }

    return back();

}
我有两个错误
当我点击第一个按钮 Undefined index: product_id 当我点击第二个 Object of class Illuminate\Database\Eloquent\Collection could not be converted to number

to94eoyn

to94eoyn1#

这里稍加修改,还尝试为订购按钮制作另一个功能和路线
改变

$current = Order::where('order_status','Delivered')->get();

$current = Order::where('order_status','Delivered')->sum('quantity');

现在可以了

Dvproduct::where('product_id',$data['product_id'])->update( ['quantity'=>$current - $data['quantity']] );

相关问题