diff --git a/app/Concert.php b/app/Concert.php index d206dbe..2c1181a 100644 --- a/app/Concert.php +++ b/app/Concert.php @@ -58,7 +58,10 @@ class Concert extends Model throw new NotEnoughTicketsException; } - $order = $this->orders()->create(['email' => $email]); + $order = $this->orders()->create([ + 'email' => $email, + 'amount' => $ticketQuantity * $this->ticket_price, + ]); foreach ($tickets as $ticket) { $order->tickets()->save($ticket); diff --git a/app/Order.php b/app/Order.php index 1c2392f..8350c38 100644 --- a/app/Order.php +++ b/app/Order.php @@ -37,7 +37,7 @@ class Order extends Model return [ 'email' => $this->email, 'ticket_quantity' => $this->ticketQuantity(), - 'amount' => $this->ticketQuantity() * $this->concert->ticket_price, + 'amount' => $this->amount, ]; } } diff --git a/database/migrations/2016_11_08_205823_create_orders_table.php b/database/migrations/2016_11_08_205823_create_orders_table.php index ef239ee..af6bd96 100644 --- a/database/migrations/2016_11_08_205823_create_orders_table.php +++ b/database/migrations/2016_11_08_205823_create_orders_table.php @@ -16,6 +16,7 @@ class CreateOrdersTable extends Migration Schema::create('orders', function (Blueprint $table) { $table->increments('id'); $table->unsignedInteger('concert_id'); + $table->integer('amount'); $table->string('email'); $table->timestamps(); });