Files
ticketbeast/app/Ticket.php
2016-12-09 16:29:27 -05:00

37 lines
652 B
PHP

<?php
namespace App;
use Carbon\Carbon;
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 reserve()
{
$this->update(['reserved_at' => Carbon::now()]);
}
public function release()
{
$this->update(['reserved_at' => null]);
}
public function concert()
{
return $this->belongsTo(Concert::class);
}
public function getPriceAttribute()
{
return $this->concert->ticket_price;
}
}