mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-14 15:53:05 +00:00
5.1 - Persisting the Order Amount
This commit is contained in:
@@ -58,7 +58,10 @@ class Concert extends Model
|
|||||||
throw new NotEnoughTicketsException;
|
throw new NotEnoughTicketsException;
|
||||||
}
|
}
|
||||||
|
|
||||||
$order = $this->orders()->create(['email' => $email]);
|
$order = $this->orders()->create([
|
||||||
|
'email' => $email,
|
||||||
|
'amount' => $ticketQuantity * $this->ticket_price,
|
||||||
|
]);
|
||||||
|
|
||||||
foreach ($tickets as $ticket) {
|
foreach ($tickets as $ticket) {
|
||||||
$order->tickets()->save($ticket);
|
$order->tickets()->save($ticket);
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class Order extends Model
|
|||||||
return [
|
return [
|
||||||
'email' => $this->email,
|
'email' => $this->email,
|
||||||
'ticket_quantity' => $this->ticketQuantity(),
|
'ticket_quantity' => $this->ticketQuantity(),
|
||||||
'amount' => $this->ticketQuantity() * $this->concert->ticket_price,
|
'amount' => $this->amount,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ class CreateOrdersTable extends Migration
|
|||||||
Schema::create('orders', function (Blueprint $table) {
|
Schema::create('orders', function (Blueprint $table) {
|
||||||
$table->increments('id');
|
$table->increments('id');
|
||||||
$table->unsignedInteger('concert_id');
|
$table->unsignedInteger('concert_id');
|
||||||
|
$table->integer('amount');
|
||||||
$table->string('email');
|
$table->string('email');
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user