title: Query where column is in another table - laravel
body: <p>I have 3 tables called <strong>categories</strong>, <strong>seasons</strong> and <strong>movies</strong>.</p>
  
  <p><strong>categories table</strong></p>
  
  <pre>
  +----+---------+------------+-------------+
  | id |   name  |    slug    | created_at  |
  +----+---------+------------+-------------+
  |  1 |    It   |  it-2017   |  SOME TIME  |
  |  2 | Another |  another   |  SOME TIME  |
  |  3 |SpiderMan| spider-man |  SOME TIME  |
  |  4 |  Cars 3 |   cars-3   |  SOME TIME  |
  +----+---------+------------+-------------+
  </pre>
  
  <p><strong>seasons table</strong></p>
  
  <pre>
  +----+---------+------------+-------------+
  | id |  number |category_id | created_at  |
  +----+---------+------------+-------------+
  |  1 |    1    |     2      |  SOME TIME  |
  |  2 |    2    |     2      |  SOME TIME  |
  |  3 |    1    |     3      |  SOME TIME  |
  |  4 |    3    |     1      |  SOME TIME  |
  +----+---------+------------+-------------+
  </pre>
  
  <p><strong>movies table</strong></p>
  
  <pre>
  +----+---------+------------+-------------+
  | id |   name  |    slug    |  season_id  |
  +----+---------+------------+-------------+
  |  1 |  Pilot  |   pilot    |      1      |
  |  2 |  Second |   second   |      1      |
  |  3 |  Third  |   third    |      1      |
  |  4 |  Fourth |   fourth   |      1      |
  +----+---------+------------+-------------+
  </pre>
  
  <p>And I made that URL is going to something like this</p>
  
  <p><em>mywebpage.com/serie/{category_slug}/season-{season_number}</em></p>
  
  <p>But where I go to this URL, query is going to show all movies in all seasons.
  Not the season from current category.</p>
  
  <p>My Controller</p>
  
  <pre><code>public function getMovies($category_slug, $season_number)
  {
    $categories = Category::where('slug', $category_slug)-&gt;get();
    $seasons = Season::with('movies')-&gt;where('number', $season_number)-&gt;get();
  
    return view('routes.getMovies', compact('categories', 'seasons'));
  }
  </code></pre>
  
  <p>And my view <strong>getMovies.blade.php</strong></p>
  
  <pre><code>@foreach($categories as $category)
      @foreach ($seasons as $season)
        @foreach ($season-&gt;movies as $movie)
          Season - {{ $season-&gt;number }}
          {{ $movie-&gt;name }}
          {{ $movie-&gt;description }}
        @endforeach
      @endforeach
  @endforeach
  </code></pre>
  
  <p>And my output is like Season 1 from all categories, but I want only to show seasons from current <strong>Category</strong>.</p>