title: laravel belongstomany with condition
body: <p>I have the following model.</p>
  <pre><code>class Training extends \Eloquent {
  
      // Add your validation rules here
      public static $rules = [
          'name' =&gt; 'required',
          'city' =&gt; 'required',
          'province' =&gt; 'required',
          'budget_year' =&gt; 'required|integer',
          's_date' =&gt; 'required|date',
          'e_date' =&gt; 'required|date'
      ];
  
      // Don't forget to fill this array
      protected $fillable = [
          'name',
          'city',
          'province',
          'budget_year',
          's_date',
          'e_date'
      ];
  
      public function material(){
          return $this-&gt;hasMany('Material');
      }
  
      public function budget(){
          return $this-&gt;belongsToMany('Budget')-&gt;withPivot('amount');
      }
  
      public function budgetById($training_id){
          $this-&gt;belongsToMany('Budget')-&gt;where('training_id', '=', $training_id)-&gt;get();
      }
  
  }
  </code></pre>
  <p>when I debug the <code>budgetById</code> method using <code>DB::getQueryLog</code>, the query is as follow</p>
  <pre><code>select budgets.*, 
  budget_training.training_id as pivot_training_id, 
  budget_training.budget_id as pivot_budget_id 
  from budgets inner join budget_training on budgets.id = budget_training.budget_id 
  where budget_training.training_id is null and training_id='6'
  </code></pre>
  <p>which return 0 rows, but when I try to modify the query and run it in pgadmin, the following script works well.</p>
  <pre><code>select budgets.*, 
  budget_training.training_id as pivot_training_id, 
  budget_training.budget_id as pivot_budget_id 
  from budgets inner join budget_training on budgets.id = budget_training.budget_id 
  where budget_training.training_id='6'
  </code></pre>
  <p>notice I remove <code>training_id is null and</code> from Laravel generated query. What is wrong with my <code>budgetById</code> method?</p>