Laravel returning null value with where method (if variable is passed)
我正在尝试在 laravel 查询中使用 where 方法。我有一个包含两个值的字符串(用逗号分隔)。我需要使用逗号后的值进行搜索。所以我使用
这是代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $vehicles_name_trim_ar = explode(',', Input::get('vehicles_name_trim')); print_r of $vehicles_name_trim_ar is Array ( [0] => A3 [1] => 2.0T Premium Automatic ) //storing both values in seperate variable $model_name = $vehicles_name_trim_ar[0]; $model_trim = $vehicles_name_trim_ar[1]; $model = Model::where('model_trim', $model_trim)->get(); |
它返回空白结果。但是,如果我证明静态值,它会返回结果
1 | $model = Model::where('model_trim',"2.0T Premium Automatic")->get(); |
我做错了什么?
您在第二个值的开头有一个空格。试试这个: