app/Http/Controllers/TransactionController.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)
    {
        $data = $request->all();
        $number = $this->transaction->generateTransactionNumber();
        DB::transaction(function() use ($data, $number) {
            $transaction = $this->transaction->create([
                'number' => $number,
                'receiver' => $data['receiver'],
                'user_id'=> auth()->id(),
                'total' => $data['total'],
                'shipping_address' => $data['address'],
                'phone_number' => $data['contact']
            ]);
            foreach ($data['products'] as $key => $product) {
                $this->transactionDetail->create([
                    'transaction_id' => $transaction->id,
                    'product_id' => $product['id'],
                    'qty' => $product['qty'],
                    'price' => $product['rawPrice'],
                    'size_id' => $this->product->getSizeId($product['id'], $product['size'])
                ]);
            }
        }, 3);
        return response()->json([
            'status' => 'data created',
            'number' => $number
        ], 201);
    }
public function store ( Request $ request ) { $ data = $ request -> all ( ) ; $ number = $ this -> transaction -> generateTransactionNumber ( ) ; DB :: transaction ( function ( ) use ( $ data , $ number ) { $ transaction = $ this -> transaction -> create ( [ 'number' => $ number , 'receiver' => $ data [ 'receiver' ] , 'user_id' => auth ( ) -> id ( ) , 'total' => $ data [ 'total' ] , 'shipping_address' => $ data [ 'address' ] , 'phone_number' => $ data [ 'contact' ] ] ) ; foreach ( $ data [ 'products' ] as $ key => $ product ) { $ this -> transactionDetail -> create ( [ 'transaction_id' => $ transaction -> id , 'product_id' => $ product [ 'id' ] , 'qty' => $ product [ 'qty' ] , 'price' => $ product [ 'rawPrice' ] , 'size_id' => $ this -> product -> getSizeId ( $ product [ 'id' ] , $ product [ 'size' ] ) ] ) ; } } , 3 ) ; return response ( ) -> json ( [ 'status' => 'data created' , 'number' => $ number ] , 201 ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .