cineflex/app/Models/Seat.php

55 lines
1.3 KiB
PHP
Raw Normal View History

2022-11-23 09:32:34 +01:00
<?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')
'room_id',
];
protected $hidden = [
'created_at',
'updated_at',
];
public function room()
{
return $this->belongsTo(Room::class, 'room_id', 'room_id');
}
public function orders()
{
return $this->belongsToMany(Order::class, 'order_seats', 'seat_id', 'order_id');
}
public function tickets()
{
return $this->hasMany(Ticket::class, 'seat_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 is_reserved(int $showing_id)
{
$tickets = $this->tickets()->where('showing_id', $showing_id)->get();
foreach ($tickets as $ticket) {
if ($ticket->order->order_status == 'pending' || $ticket->order->order_status == 'paid') {
return true;
}
}
return false;
}
2022-11-23 09:32:34 +01:00
}