mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-04 18:48:43 +00:00
3.2 - Adding Tickets to Concerts
This commit is contained in:
@@ -34,14 +34,32 @@ class Concert extends Model
|
||||
return $this->hasMany(Order::class);
|
||||
}
|
||||
|
||||
public function tickets()
|
||||
{
|
||||
return $this->hasMany(Ticket::class);
|
||||
}
|
||||
|
||||
public function orderTickets($email, $ticketQuantity)
|
||||
{
|
||||
$order = $this->orders()->create(['email' => $email]);
|
||||
$tickets = $this->tickets()->take($ticketQuantity)->get();
|
||||
|
||||
foreach (range(1, $ticketQuantity) as $i) {
|
||||
$order->tickets()->create([]);
|
||||
foreach ($tickets as $ticket) {
|
||||
$order->tickets()->save($ticket);
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
public function addTickets($quantity)
|
||||
{
|
||||
foreach (range(1, $quantity) as $i) {
|
||||
$this->tickets()->create([]);
|
||||
}
|
||||
}
|
||||
|
||||
public function ticketsRemaining()
|
||||
{
|
||||
return $this->tickets()->whereNull('order_id')->count();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user