app/Http/Controllers/OrderController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        DB::transaction(function () use ($request) {
            $orders = new Order;
            $orders->name = $request->customer_name;
            $orders->phone = $request->customer_phone;
            $orders->save();
            $order_id = $orders->id;
            for($product_id= 0; $product_id < is_countable($request->product_id); $product_id++){
                $order_details = new Order_Detail;
                $order_details->order_id = $order_id;
                $order_details->product_id = $request->product_id[$product_id];
                $order_details->unitprice = $request->price[$product_id];
                $order_details->quantity = $request->quantity[$product_id];
                $order_details->discount = $request->discount[$product_id];
                $order_details->amount = $request->total_amount[$product_id];
                $order_details->save();
            }
            $transactions = new Transaction();
            $transactions->order_id = $order_id;
            $transactions->user_id = auth()->user()->id; 
            $transactions->balance = $request->balance;
            $transactions->paid_amount = $request->paid_amount;
            $transactions->payment_method = $request->payment_method;
            $transactions->transac_amount = $order_details->amount;
            $transactions->transac_date = date('y-m-d');
            $transactions->save();
            Cart::where('user_id',auth()->user()->id)->delete();
            $products = Product::all();
            $order_details = Order_Detail::where('order_id', $orders->id)->get();
            $orderedBy = Order::where('id', $orders->id)->get();
            return view('orders.index',
                 [
                    'products'=> $products,
                    'order_details'=> $order_details,
                    'customer_orders' => $orderedBy
                 ]);
        });
       return back()->with( " you have successfully order for a product");
    }
public function store ( Request $ request ) { DB :: transaction ( function ( ) use ( $ request ) { $ orders = new Order ; $ orders -> name = $ request -> customer_name ; $ orders -> phone = $ request -> customer_phone ; $ orders -> save ( ) ; $ order_id = $ orders -> id ; for ( $ product_id = 0 ; $ product_id < is_countable ( $ request -> product_id ) ; $ product_id ++ ) { $ order_details = new Order_Detail ; $ order_details -> order_id = $ order_id ; $ order_details -> product_id = $ request -> product_id [ $ product_id ] ; $ order_details -> unitprice = $ request -> price [ $ product_id ] ; $ order_details -> quantity = $ request -> quantity [ $ product_id ] ; $ order_details -> discount = $ request -> discount [ $ product_id ] ; $ order_details -> amount = $ request -> total_amount [ $ product_id ] ; $ order_details -> save ( ) ; } $ transactions = new Transaction ( ) ; $ transactions -> order_id = $ order_id ; $ transactions -> user_id = auth ( ) -> user ( ) -> id ; $ transactions -> balance = $ request -> balance ; $ transactions -> paid_amount = $ request -> paid_amount ; $ transactions -> payment_method = $ request -> payment_method ; $ transactions -> transac_amount = $ order_details -> amount ; $ transactions -> transac_date = date ( 'y-m-d' ) ; $ transactions -> save ( ) ; Cart :: where ( 'user_id' , auth ( ) -> user ( ) -> id ) -> delete ( ) ; $ products = Product :: all ( ) ; $ order_details = Order_Detail :: where ( 'order_id' , $ orders -> id ) -> get ( ) ; $ orderedBy = Order :: where ( 'id' , $ orders -> id ) -> get ( ) ; return view ( 'orders.index' , [ 'products' => $ products , 'order_details' => $ order_details , 'customer_orders' => $ orderedBy ] ) ; } ) ; return back ( ) -> with ( "  you have successfully order for a product " ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//to  store all the content to the database // note for this to work no that you downloaded php namespace resolver for it , it is in the extension window sha or just type use DB //order model //order name and phone no used to in the form // order_details model //transaction model // last Order History