title: access to query in model.php laravel
body: <p>I have a relation and a function in my User.php;</p>
  <pre><code>class User extends Model
  {
      public function children()
      {
          return $this-&gt;hasMany(self::class, 'level1_user_id')
              -&gt;select(['id', 'first_name', 'last_name', 'level1_user_id']);
      }
  
      public function grandchildren()
      {
          return $this-&gt;children()-&gt;with(['grandchildren']);
      }
  }
  </code></pre>
  <p>and this is my controller.php:</p>
  <pre><code>public function allChildren()
  {
      $user = User::where('id', 3)-&gt;with(['grandchildren' =&gt;
          function ($query) {
              $query-&gt;where('first_name', 'rose');
          }
      ])-&gt;first();
      return $user;
  }
  </code></pre>
  <p>when I attach grandchildren it returns all nodes of that tree;
  I want to assign a condition and get nodes that their name is 'rose', but I can do this just for first level; how can I access this query:</p>
  <pre><code> $query-&gt;where('first_name', 'rose');
  </code></pre>
  <p>in my User.php in grandchildren function to set the query for others too?</p>
  <p>I want to do sth like this:</p>
  <pre><code>class User extends Model
  {
      public function children()
      {
          return $this-&gt;hasMany(self::class, 'level1_user_id')
              -&gt;select(['id', 'first_name', 'last_name', 'level1_user_id']);
      }
  
      public function grandchildren(Query $inputQuery)
      {
          return $this-&gt;children()-&gt;with(['grandchildren' =&gt; function ($query) use ($inputQuery) {
          $query-&gt;$inputQuery;
      }]);
      }
  }
  </code></pre>