2022-11-23 09:32:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
2023-01-01 20:13:11 +01:00
|
|
|
use Carbon\Carbon;
|
2022-11-23 09:32:34 +01:00
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Movie Theater Showings
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Showing extends Model
|
|
|
|
{
|
|
|
|
|
|
|
|
protected $table = 'showings';
|
|
|
|
protected $primaryKey = 'showing_id';
|
|
|
|
protected $fillable = [
|
|
|
|
'movie_id',
|
|
|
|
'showing_start',
|
|
|
|
'room_id', // which room is showing the movie?
|
|
|
|
'user_id', // who added the showing?
|
|
|
|
];
|
|
|
|
|
|
|
|
protected $hidden = [
|
|
|
|
'created_at',
|
|
|
|
'updated_at',
|
|
|
|
];
|
|
|
|
|
2022-12-08 09:30:07 +01:00
|
|
|
public static function findOrfail($id)
|
|
|
|
{
|
|
|
|
return Showing::where('showing_id', $id)->firstOrFail();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function room()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Room::class, 'room_id', 'room_id');
|
|
|
|
}
|
|
|
|
|
2022-11-23 09:32:34 +01:00
|
|
|
public function movie()
|
|
|
|
{
|
|
|
|
return $this->belongsTo(Movie::class, 'movie_id', 'movie_id');
|
|
|
|
}
|
|
|
|
|
2023-02-02 08:17:38 +01:00
|
|
|
public function prices()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Price::class, 'showing_id', 'showing_id');
|
|
|
|
}
|
|
|
|
|
2022-11-23 09:32:34 +01:00
|
|
|
public function nowPlaying()
|
|
|
|
{
|
|
|
|
return $this->where('showing_start', '>=', now())->get();
|
|
|
|
}
|
|
|
|
|
2023-02-02 08:17:38 +01:00
|
|
|
public function showing_end() {
|
2023-01-01 20:13:11 +01:00
|
|
|
$date = new Carbon($this->showing_start);
|
|
|
|
$date->addMinutes($this->movie->movie_length);
|
|
|
|
return $date;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tickets()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Ticket::class, 'showing_id', 'showing_id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function tickets_available() {
|
|
|
|
$tickets = $this->room->seats()->count();
|
|
|
|
$tickets_sold = $this->tickets()->count();
|
|
|
|
return $tickets - $tickets_sold;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function find($id)
|
|
|
|
{
|
|
|
|
return Showing::where('showing_id', $id)->first();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function seatMatrix() {
|
|
|
|
return $this->room->seatMatrix($this->showing_id);
|
|
|
|
}
|
2022-11-23 09:32:34 +01:00
|
|
|
}
|