Question

I'm trying to use a where method in laravel query. i have a string containing two values (separated by comma). I need to search with value that is after the comma. So i used explode php function to make an array . So I get an array containing two key-value pairs. i want to use 2nd value to search database. So i'm storing the second value in a variable and then passing that variable in the where method. But it's returning blank collection object

Here's the code

$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();

It's returning blank result. However if i'm proving static value, it return the result

$model = Model::where('model_trim', "2.0T Premium Automatic")->get();

What am i doing wrong?

Was it helpful?

Solution

You have a space at the start of the second value. try this:

$model_name = trim($vehicles_name_trim_ar[0]);
$model_trim = trim($vehicles_name_trim_ar[1]);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top