mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
44 lines
757 B
PHP
44 lines
757 B
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Order extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
public function concert()
|
|
{
|
|
return $this->belongsTo(Concert::class);
|
|
}
|
|
|
|
public function tickets()
|
|
{
|
|
return $this->hasMany(Ticket::class);
|
|
}
|
|
|
|
public function ticketQuantity()
|
|
{
|
|
return $this->tickets()->count();
|
|
}
|
|
|
|
public function cancel()
|
|
{
|
|
foreach ($this->tickets as $ticket) {
|
|
$ticket->release();
|
|
}
|
|
|
|
$this->delete();
|
|
}
|
|
|
|
public function toArray()
|
|
{
|
|
return [
|
|
'email' => $this->email,
|
|
'ticket_quantity' => $this->ticketQuantity(),
|
|
'amount' => $this->amount,
|
|
];
|
|
}
|
|
}
|