title: Laravel: Pass Parameter to Relationship Function?
body: <p>Is it possible to pass, somehow, a parameter to a relationship function?</p>
  
  <p>I have currently the following:</p>
  
  <pre><code>public function achievements()
  {
       return $this-&gt;belongsToMany('Achievable', 'user_achievements')-&gt;withPivot('value', 'unlocked_at')-&gt;orderBy('pivot_unlocked_at', 'desc');
  }
  </code></pre>
  
  <p>The problem is that, in some cases, it does not fetch the unlocked_at column and it returns an error.</p>
  
  <p>I have tried to do something like:</p>
  
  <pre><code>public function achievements($orderBy = true)
  {
  $result = $this-&gt;belongsToMany (...)
  if($orderBy) return $result-&gt;orderBy(...)
  return $result;
  }
  </code></pre>
  
  <p>And call it as:</p>
  
  <pre><code>$member-&gt;achievements(false)-&gt;(...)
  </code></pre>
  
  <p>But this does not work. Is there a way to pass parameters into that function or any way to check if the <code>pivot_unlocked_at</code> is being used?</p>