0

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?

1
  • You better use var_dump instead of print_r as it will be clearer what the result of the explode function is. Commented Jul 29, 2014 at 5:55

1 Answer 1

1

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]);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Did't notice that. Many Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.