app/Http/Controllers/OrdersController.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)
    {
        if(auth()->user()->isClient()){
            $order = Order::find($id);
            if($order === null || $order->user_id !== auth()->user()->id) abort(404);
            if($order->status == 0){ 
                foreach($order->order_products as $order_product){
                    $product = $order_product->getProduct();
                    if($product === null) abort(404);
                    $order_product->code = $product->code;
                    $order_product->name = $product->name;
                    $order_product->price = $product->price;
                    $order_product->currency = $product->currency;
                    $order_product->unit = $product->unit;
                    $order_product->discount = $product->getDiscount(auth()->user());
                    $order_product->save();
                }
                $order->status = 1;
                $order->save();
                session()->forget('current_order');
            }
            return redirect('/orders/status/1')->with('top_notfication_success', __('notifications.order_confirmation', ['order'=>$order->id, 'email'=>auth()->user()->email]));
        }
        else abort(404);
    }
public function update ( Request $ request , $ id ) { if ( auth ( ) -> user ( ) -> isClient ( ) ) { $ order = Order :: find ( $ id ) ; if ( $ order === null || $ order -> user_id !== auth ( ) -> user ( ) -> id ) abort ( 404 ) ; if ( $ order -> status == 0 ) { foreach ( $ order -> order_products as $ order_product ) { $ product = $ order_product -> getProduct ( ) ; if ( $ product === null ) abort ( 404 ) ; $ order_product -> code = $ product -> code ; $ order_product -> name = $ product -> name ; $ order_product -> price = $ product -> price ; $ order_product -> currency = $ product -> currency ; $ order_product -> unit = $ product -> unit ; $ order_product -> discount = $ product -> getDiscount ( auth ( ) -> user ( ) ) ; $ order_product -> save ( ) ; } $ order -> status = 1 ; $ order -> save ( ) ; session ( ) -> forget ( 'current_order' ) ; } return redirect ( '/orders/status/1' ) -> with ( 'top_notfication_success' , __ ( 'notifications.order_confirmation' , [ 'order' => $ order -> id , 'email' => auth ( ) -> user ( ) -> email ] ) ) ; } else abort ( 404 ) ; }
Update the specified resource in storage.
Update the specified resource in storage .
// Client submits order // Write info for every product