amazon-dash-button/app/Repositories/OrderRepository.php
/**
     * Create an order from a dash button.
     */
Create an order from a dash button.
Create an order from a dash button .
public function createDashOrder(User $user, Product $product, int $quantity = 1): Order
    {
        $order = DB::transaction(function () use ($user, $product, $quantity) {
            $order = new Order();
            $order->user()->associate($user);
            $order->save();
            $item = new OrderItem();
            $item->product()->associate($product);
            $item->amount = $product->price;
            $item->currency = $product->currency;
            $item->quantity = $quantity;
            $order->items()->save($item);
            return $order;
        });
        Log::debug('Created a new order.', [
            'order_id' => $order->id,
            'user_id' => $order->user->id,
        ]);
        return $order;
    }
public function createDashOrder ( User $ user , Product $ product , int $ quantity = 1 ) : Order { $ order = DB :: transaction ( function ( ) use ( $ user , $ product , $ quantity ) { $ order = new Order ( ) ; $ order -> user ( ) -> associate ( $ user ) ; $ order -> save ( ) ; $ item = new OrderItem ( ) ; $ item -> product ( ) -> associate ( $ product ) ; $ item -> amount = $ product -> price ; $ item -> currency = $ product -> currency ; $ item -> quantity = $ quantity ; $ order -> items ( ) -> save ( $ item ) ; return $ order ; } ) ; Log :: debug ( 'Created a new order.' , [ 'order_id' => $ order -> id , 'user_id' => $ order -> user -> id , ] ) ; return $ order ; }
Create an order from a dash button.
Create an order from a dash button .