mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-05 01:48:46 +00:00
2.6 - Encapsulating Relationship Logic in the Model
This commit is contained in:
@@ -33,4 +33,15 @@ class Concert extends Model
|
||||
{
|
||||
return $this->hasMany(Order::class);
|
||||
}
|
||||
|
||||
public function orderTickets($email, $ticketQuantity)
|
||||
{
|
||||
$order = $this->orders()->create(['email' => $email]);
|
||||
|
||||
foreach (range(1, $ticketQuantity) as $i) {
|
||||
$order->tickets()->create([]);
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user