54 lines
1.3 KiB
PHP
54 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Seat extends Model
|
|
{
|
|
|
|
protected $table = 'seats';
|
|
protected $primaryKey = 'seat_id';
|
|
public $timestamps = false;
|
|
protected $fillable = [
|
|
'seat_row',
|
|
'seat_number',
|
|
'seat_type', // enum('standard', 'wheelchair', 'loveseat', 'not_available')
|
|
'seat_linked_id', // if this is a loveseat, this is the other seat
|
|
'room_id',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'created_at',
|
|
'updated_at',
|
|
];
|
|
|
|
public function room()
|
|
{
|
|
return $this->belongsTo(Room::class, 'room_id', 'room_id');
|
|
}
|
|
|
|
public function tickets()
|
|
{
|
|
return $this->hasMany(Ticket::class, 'seat_id', 'seat_id');
|
|
}
|
|
|
|
public function linked_seat()
|
|
{
|
|
return $this->belongsTo(Seat::class, 'seat_linked_id', 'seat_id');
|
|
}
|
|
|
|
// isReserved(int showing_id) method
|
|
// Looks at showing / order / ticket if it's reserved
|
|
// Returns true if it is reserved, false if it isn't
|
|
public function isReserved(int $showing_id): bool
|
|
{
|
|
$tickets = $this->tickets->where('showing_id', $showing_id);
|
|
foreach ($tickets as $ticket) {
|
|
if ($ticket->showing_id == $showing_id) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|