mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-02-04 13:48:56 +00:00
5.4 - Extracting a Named Constructor
This commit is contained in:
@@ -8,6 +8,20 @@ class Order extends Model
|
||||
{
|
||||
protected $guarded = [];
|
||||
|
||||
public static function forTickets($tickets, $email)
|
||||
{
|
||||
$order = self::create([
|
||||
'email' => $email,
|
||||
'amount' => $tickets->sum('price'),
|
||||
]);
|
||||
|
||||
foreach ($tickets as $ticket) {
|
||||
$order->tickets()->save($ticket);
|
||||
}
|
||||
|
||||
return $order;
|
||||
}
|
||||
|
||||
public function concert()
|
||||
{
|
||||
return $this->belongsTo(Concert::class);
|
||||
|
||||
Reference in New Issue
Block a user