0

I am getting this error saying "Undefined variable: stq" and the variable is there. I looked to see if I missed something but I don't see what I'm missing. What is the problem?

Here is my code

$stq=str_replace(", ", " ,", $userinputt);

   $pro=User::Where('tags','Like','%'. $str .'%')->Where(function ($query) use($strrr,$strr,$strrrr) {
    $query->Where('cityandstate', 'LIKE', '%'. $strr .'%')->orWhere('cityandstate', 'LIKE', '%'. $strrr .'%')->orWhere('cityandstate', 'LIKE', '%'. $strrrr .'%')->orWhere('cityandstate', 'LIKE', '%'. $stq .'%');

Thanks in advance

GCode22
  • 47
  • 6
  • 2
    With variables like `$strrr`, `$strr`, `$strrrr`, who needs enemies? – bishop Sep 17 '18 at 16:57
  • Possible duplicate of [Reference - What does this error mean in PHP?](https://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – bishop Sep 17 '18 at 16:58
  • Lol! The other variable $strr, $strrr, $strrrr there okay. Its just when i added the $stq it told me it was undefined as if the varibles not there. – GCode22 Sep 17 '18 at 16:59

1 Answers1

3

You need to pass the $stq variable in the function like this

$stq=str_replace(", ", " ,", $userinputt);

 $pro=User::Where('tags','Like','%'. $str .'%')
->Where(function ($query) use($strrr,$strr,$strrrr,$stq) {

$query->Where('cityandstate', 'LIKE', '%'. $strr .'%')
->orWhere('cityandstate', 'LIKE', '%'. $strrr .'%')
->orWhere('cityandstate', 'LIKE', '%'. $strrrr .'%')
->orWhere('cityandstate', 'LIKE', '%'. $stq .'%');
Gurpal singh
  • 1,511
  • 1
  • 14
  • 27