Doaa Magdy Doaa Magdy - 1 year ago 100
PHP Question

Laravel 5.0 Query Builder - Where with multiple parameters

I've a Laravel 5.0 project, that I need to implement the following logic

$var1= 'A';
$var2= 'B';
$var3= 50;
$data = DataModel::select('attr1','attr2')->where(function($q){

The problem is for the "Where" function $var1, var2 and $var3 are undefined variables.

My Question is, How can I pass multiple parameters to the where function?

Answer Source

Here, closure function passed in where argument. To inherit variables you have to use use keyword

For example function($q) use($var1, $var2, $var3){...

To learn more about closure function please check php manual.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download