cineflex/app/Models/Showing.php

48 lines
928 B
PHP

<?php
namespace App\Models;
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',
];
public static function findOrfail($id)
{
return Showing::where('showing_id', $id)->firstOrFail();
}
public function room()
{
return $this->belongsTo(Room::class, 'room_id', 'room_id');
}
public function movie()
{
return $this->belongsTo(Movie::class, 'movie_id', 'movie_id');
}
public function nowPlaying()
{
return $this->where('showing_start', '>=', now())->get();
}
}