app/Http/Controllers/OrderController.php
/**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
Update the specified resource in storage.
Update the specified resource in storage .
public function update(Request $request, $id)
    {
        $order=Order::find($id);
        $this->validate($request,[
            'status'=>'required|in:new,process,delivered,cancel'
        ]);
        $data=$request->all();
        if($request->status=='delivered'){
            foreach($order->cart as $cart){
                $product=$cart->product;
                $product->stock -=$cart->quantity;
                $product->save();
            }
        }
        $status=$order->fill($data)->save();
        if($status){
            request()->session()->flash('success','Successfully updated order');
        }
        else{
            request()->session()->flash('error','Error while updating order');
        }
        return redirect()->route('order.index');
    }
public function update ( Request $ request , $ id ) { $ order = Order :: find ( $ id ) ; $ this -> validate ( $ request , [ 'status' => 'required|in:new,process,delivered,cancel' ] ) ; $ data = $ request -> all ( ) ; if ( $ request -> status == 'delivered' ) { foreach ( $ order -> cart as $ cart ) { $ product = $ cart -> product ; $ product -> stock -= $ cart -> quantity ; $ product -> save ( ) ; } } $ status = $ order -> fill ( $ data ) -> save ( ) ; if ( $ status ) { request ( ) -> session ( ) -> flash ( 'success' , 'Successfully updated order' ) ; } else { request ( ) -> session ( ) -> flash ( 'error' , 'Error while updating order' ) ; } return redirect ( ) -> route ( 'order.index' ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// return $request->status; // return $product;