3

I have an array to perform a where statement:

$array = ['name' => 'Jhon', 'age' => '27'];
User::where($array);

I need to use the same array to perform a search between two different age, I need something like:

User::where('age', '>=', '28')->where('age' , '<=', 50);

How should I do that using the above array?

2
  • What do you mean by "I need to use the same array to perform a search between two different age"? The array you showcased only contains one age. Please clarify what array structure you want for the age range. Commented Jan 22, 2016 at 19:47
  • That was just an example, its not actual data. I want to know how can I search all the records between two ages without use the chain methods but just pass and array to the where with the ages range Commented Jan 22, 2016 at 19:51

1 Answer 1

1

You can use the whereBetween method:

User::whereBetween('age', [28, 50]);

You can read more about what conditions you can use in the Where Clauses documentation.

Sign up to request clarification or add additional context in comments.

Comments

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.