title: Laravel 5.4: Call to undefined method Illuminate/Database/Query/Builder::getRelated()
body: <p>I've been working on this for a week now, what I want to happen is that, to select the Level Rewards that have not been claimed by the user, but I'm getting an error which says: call to undefined <code>method::getRelated()</code>.</p>
  
  <p>The claim_rewards table consists of </p>
  
  <pre><code>id, reward_id, user_id, status
  </code></pre>
  
  <p>So, if a user have 3 rewards to be claimed, and the user claims one reward, only the two remaining rewards should be displayed on the field, so I supposed a 'whereDoesNotHave' clause should work out, but I can't figure out how to fulfill the code to make it work.</p>
  
  <p>Here is the code of the two scopes:</p>
  
  <pre><code>public function scopeClaimLevel($query)
  {
      return $query-&gt;join('claim_rewards','claim_rewards.reward_id','=','level_rewards.id')-&gt;select('level_rewards.*');
  }
  
  public function scopeRewards($query)
  {
     return $query = LevelRewards::whereDoesntHave('claimLevel')-&gt;whereDoesntHave('claim_rewards.status','=','0')-&gt;get();
  }
  </code></pre>
  
  <p>I even tried this: </p>
  
  <pre><code>public function scopeGetRewards($query)
  {
      return $query-&gt;claimLevel()
      -&gt;whereDoesntHave('claimLevel', function (Builder $query) {
             $query-&gt;where('claim_rewards.status', '=', '0');
       }) 
      -&gt;select('level_rewards.*')-&gt;get();
  }
  </code></pre>
  
  <p>I even included this on the <code>LevelRewards</code> model:</p>
  
  <pre><code>use App\ClaimReward;
  </code></pre>
  
  <p>But I still get the same error. Any ideas on how to deal with this? Thank you.</p>
  
  <p>Edit:</p>
  
  <p>Here is the structure for the level_rewards table</p>
  
  <pre><code>id, level_required, item_name
  </code></pre>
  
  <p>That is why I made a scope into the LevelRewards model which is</p>
  
  <pre><code>public function scopeClaimLevel($query)
  {
      return $query-&gt;join('claim_rewards','claim_rewards.reward_id','=','level_rewards.id')-&gt;select('level_rewards.*');
  }
  </code></pre>
  
  <p>So that it would result to a constraint relationship to claim_rewards table</p>
  
  <p>So if I put it into a Scenario, this will be the outcome:</p>
  
  <p>I, as a user is on a level 20. I have three rewards to claim. Now, for my lists of rewards, I have level 10, 15, and 20 rewards to claim.
  Now, I claimed the level 10 reward except for levels 15 and 20 rewards. So inside my claim_rewards table will have a data of that from level_rewards table that was claimed. Which will be the reward_id of the claim_rewards table.</p>
  
  <p>So, if the level 10 reward that was claimed has a status of zero, then it will no longer be displayed into the field. The remaining rewards to be displayed is that those from level_rewards table that doesn't have a status of zero in the claim_rewards table</p>