Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel - Where statement and array

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?

like image 626
Christian Giupponi Avatar asked Mar 15 '26 12:03

Christian Giupponi


1 Answers

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.

like image 154
Bogdan Avatar answered Mar 17 '26 02:03

Bogdan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!