title: laravel 5.4 can i use custom method inside a where clause
body: <p>I'm trying to call a method inside a custom model function during query building but getting error.This way is it possible.Actually i'm trying to break the query in two function because filterData may be long.</p>
  
  <p>In model, i wrote like this</p>
  
  <pre><code>public function get_filter_sql2($query, $filterData){
  
          if( count($filterData) &gt; 0 ){   
  
              foreach($filterData as $key=&gt;$value){   
  
                  if( $value!=''){
  
                      if( $key == 'title' ){
                          $query-&gt;where('b.title', 'LIKE', '%'.$value.'%');
                      }
                      if( $key == 'bannercatID' ){
                          $query-&gt;where('b.bannercatID', '=', $value);
                      }
                      if( $key == 'status' ){
                          $query-&gt;where('b.status', '=', $value);
                      }
  
                  }
              }
          }   
          return $query; 
      }
  
  
  
  function scopeGet_all_records2($query,$filterData, $per_page){ 
          //DB::enableQueryLog();
          $result = DB::table('banner as b')
                  -&gt;leftJoin('banner_category as bc', 'bc.bannercatID', '=', 'b.bannercatID')    
                  -&gt;select('*')           
                  -&gt;where( function ($query) use ($filterData){               
                      $this-&gt;get_filter_sql2($query, $filterData);
                   })         
                  -&gt;orderBy('b.bannercatID', 'ASC')
                  -&gt;paginate($per_page)
                  ;
          //$result = DB::getQueryLog(); 
          //print_r($result);
          if( count($result) &gt; 0 ){
              $result = $result;
          }
          else{
              $result = false;
          }       
          return $result;             
  
      }
  </code></pre>