So I have a table, cities
Second table is movies,
And the third table is theatres
I have a Pivot table which connects all three of these.
What I am trying to achieve is, to get only those theatres where city_id and movie_id are a certain value.
This is my controller
class MovieController extends Controller
{
public function test(){
$city_id=1;
$movie_id=1;
$th=Movie::where('id',$movie_id)->first();
dd($th->theatre);
}
}
I want all the theatres where movie_id=1 and city_id=1
Movie Model
class Movie extends Model
{
use HasFactory;
public function theatre(){
return $this->belongsToMany(Theatre::class,'city_movie_theatre');
}
public function city(){
return $this->belongsToMany(City::class,'city_movie_theatre');
}
}
Theatre Model
class Theatre extends Model
{
use HasFactory;
public function city(){
return $this->belongsToMany(City::class,'city_movie_theatre');
}
public function movie(){
return $this->belongsToMany(Movie::class,'city_movie_theatre','theatre_id','movie_id');
}
}
Pivot Table Model
use Illuminate\Database\Eloquent\Relations\Pivot;
class City_Movie_Theatre extends Pivot
{
use HasFactory;
protected $table='city_movie_theatre';
}



