2.6 - Encapsulating Relationship Logic in the Model

This commit is contained in:
Adam Wathan
2016-11-09 11:16:34 -05:00
parent 25cc370adf
commit 7fee2b89ee
3 changed files with 24 additions and 10 deletions

View File

@@ -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;
}
}