mirror of
https://github.com/nothingworksinc/ticketbeast.git
synced 2026-01-26 11:14:06 +00:00
49 lines
924 B
PHP
49 lines
924 B
PHP
<?php
|
|
|
|
namespace App;
|
|
|
|
use Carbon\Carbon;
|
|
use App\Facades\TicketCode;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Ticket extends Model
|
|
{
|
|
protected $guarded = [];
|
|
|
|
public function scopeAvailable($query)
|
|
{
|
|
return $query->whereNull('order_id')->whereNull('reserved_at');
|
|
}
|
|
|
|
public function scopeSold($query)
|
|
{
|
|
return $query->whereNotNull('order_id');
|
|
}
|
|
|
|
public function reserve()
|
|
{
|
|
$this->update(['reserved_at' => Carbon::now()]);
|
|
}
|
|
|
|
public function release()
|
|
{
|
|
$this->update(['reserved_at' => null]);
|
|
}
|
|
|
|
public function claimFor($order)
|
|
{
|
|
$this->code = TicketCode::generateFor($this);
|
|
$order->tickets()->save($this);
|
|
}
|
|
|
|
public function concert()
|
|
{
|
|
return $this->belongsTo(Concert::class);
|
|
}
|
|
|
|
public function getPriceAttribute()
|
|
{
|
|
return $this->concert->ticket_price;
|
|
}
|
|
}
|