0

My query looks like this at the moment, it should work.

$status = 'active';

$data = DB::table('applicant')
->when($status, function($query) use ($status){
            return $query->where('Status', $status);})
->get();

But i am getting this error :

Call to undefined method Illuminate\Database\Query\Builder::when()
Matt
  • 3
  • 2

1 Answers1

0

Check your code: the Closure is not closed, try to write line 5 as follow:

return $query->where('Status', $status);})
dparoli
  • 8,891
  • 1
  • 30
  • 38
  • sorry i did have those, when i copied and pasted it did not copy. Still throws the same error, might be a version issue as it works on laravel 5.2.39 , the above version is 5.0.16 . – Matt Feb 14 '17 at 15:38
  • I think also is a version issue: the when() function was added in 5.2.34 – dparoli Feb 14 '17 at 15:54
  • do you know of an alternative way to do this ? – Matt Feb 14 '17 at 17:01
  • http://stackoverflow.com/questions/14179758/how-can-i-build-a-condition-based-query-in-laravel – dparoli Feb 15 '17 at 07:50