1

I am trying to do a function for auto generating query with advanced where for search function.

Here is my example code:

$query->where(function($thisquery){
    $datacolumn = DB::select('SHOW COLUMNS FROM '.mysql_real_escape_string($tablename));
    for($i=0;$i<sizeof($datacolumn);$i++){
        $field = $datacolumn[$i]->Field;
        $thisquery->orWhere($field,'like','%'.$keyword.'%');
    }
});

The problem is how can I pass variables into the function?

Michael Irigoyen
  • 22,513
  • 17
  • 89
  • 131
user1995781
  • 19,085
  • 45
  • 135
  • 236
  • possible duplicate of [In PHP 5.3.0, what is the function "use" identifier?](http://stackoverflow.com/questions/1065188/in-php-5-3-0-what-is-the-function-use-identifier) – Lucky Soni Feb 26 '14 at 09:24

1 Answers1

4

Use the use keyword

$query->where(function($thisquery) use ($yourVariable, $yourVariable2) {

});
Lucky Soni
  • 6,811
  • 3
  • 38
  • 57