我收到此错误,提示“未定义的变量:stq”,并且变量存在。我看我是否错过了一些东西,但看不到我缺少的东西。问题是什么?
这是我的代码
$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 .'%');
预先感谢
答案 0 :(得分:3)
您需要在函数中传递$ stq变量
$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 .'%');