title: How to add custom methods to eloquent model in a way we can chain them?
body: <p>What I want is add methods to eloquent models so I can chain them, for example:</p>
  
  <pre class="lang-php prettyprint-override"><code>class MovieResolver
  {
      public function getMoviesFeaturingToday(array $args)
      {
          // Movie is an Eloquent model
  
          $movie = (new Movie())
              -&gt;getMoviesFeaturingTodayOnTheater($args['movieTheaterId'])
              -&gt;getBySessionCategory($args['sessioncategory']);
  
          // And keep doing some operations if necessary, like the code below.
          // I cannot call the get() method unless I finish my operations.
  
          return $movie-&gt;whereDate('debut', '&lt;=', Carbon::today())
              -&gt;orderBy('debut', 'desc')
              -&gt;get();
      }
  }
  </code></pre>
  
  <p>But adding these methods to the model:</p>
  
  <pre class="lang-php prettyprint-override"><code>class Movie extends Model
  {
      public function getMoviesFeaturingTodayOnTheater($theaterId)
      {
          return $this-&gt;whereHas(
              'sessions.entries.movieTheaterRoom',
              function ($query) use ($theaterId) {
                  $query-&gt;where('movie_theater_id', $theaterId);
              }
          );
      }
  
      public function getBySessionCategory($sessionCategory)
      {
          return $this-&gt;whereHas(
  
          );
      }
  
  
  }
  </code></pre>
  
  <p>Results in the following error:</p>
  
  <blockquote>
    <p>Call to undefined method Illuminate\Database\Eloquent\Builder::getMoviesFeaturingTodayOnTheater()</p>
  </blockquote>
  
  <p>But why? What I'm doing wrong?</p>