cineflex/app/Models/Cinema.php

54 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2023-02-02 08:17:38 +01:00
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Cinema extends Model
{
use HasFactory;
protected $table = 'cinemas';
protected $primaryKey = 'cinema_id';
public $timestamps = false;
protected $fillable = [
'cinema_name',
'address_id',
'user_id', // who created this cinema
'cinema_open',
'cinema_close',
];
protected $hidden = [
'created_at',
'updated_at',
];
public function address()
{
return $this->belongsTo(Address::class, 'address_id', 'address_id');
}
public function rooms()
{
return $this->hasMany(Room::class, 'cinema_id', 'cinema_id');
}
public function showings()
{
return $this->hasManyThrough(Showing::class, Room::class, 'cinema_id', 'room_id', 'cinema_id', 'room_id');
}
public function find($id)
{
return $this->where('cinema_id', $id)->first();
}
public function users() {
//users associated
return $this->belongsToMany('App\Models\User', 'user_assignments', 'cinema_id', 'user_id');
}
}