title: Sort related table inside of the loop to build js array from php
body: <p>Quick question, I have Model that related to different model (one to many). </p>
  
  <p>I'm building method that should return js array with related table included to array. </p>
  
  <p>But I need to sort a bit <code>warrant_grants</code>, I need to return <code>$warrant_grants-&gt;where('status', active)</code>. So My <code>-&gt;where()</code> doesn't work this way: </p>
  
  <pre><code>public function warrants($company_id){
      $company = auth()-&gt;user()-&gt;companies()-&gt;findOrFail($company_id);
      $warrants = $company-&gt;warrants;
      foreach($warrants as $warrant) {
         //this doesn't work
         $warrant-&gt;warrantGrants-&gt;where('status', 'active');
      }
      $warrants = $warrants-&gt;toArray();
      return array_splice($warrants, 0);
  }
  </code></pre>
  
  <p>Relationship: </p>
  
  <pre><code>public function warrantGrants()
  {
      return $this-&gt;hasMany(WarrantGrant::class);
  }
  </code></pre>
  
  <p>Need this little help, bc it returns me data with any status, I need only 'active'</p>