我想在订单交付后减少产品数量 laravel 7
i want to reduce products quantity after an order delivered laravel 7
所以这是我确认订单已送达的按钮
@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();
}
我有 2 个错误
当我点击第一个按钮时,我得到 Undefined index: product_id
当我点击第二个时 Object of class Illuminate\Database\Eloquent\Collection could not be converted to number
Here is little correction, also try to make another function and route for ordered button
改变
$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']] );
所以这是我确认订单已送达的按钮
@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();
}
我有 2 个错误
当我点击第一个按钮时,我得到 Undefined index: product_id
当我点击第二个时 Object of class Illuminate\Database\Eloquent\Collection could not be converted to number
Here is little correction, also try to make another function and route for ordered button
改变
$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']] );