I send an array to my API made in Laravel 5 which is an array of allowed values ex: [1,3,5]
I try to do the select like this:
$json = (object)Input::all();
$loans = DB::table("loans")
->where("years", ">=", $json->year_low)
->where("years", "<=", $json->year_high)
->where("risk", $json->risks)
->get();
risks
is the array.
What I receive from the database is and empty array.
In a test I send every possible value 0...4 but I receive an empty array.
How can I select a row which a column's value exists inside an array?
If you meant $json->risks
is array like [1,2,3]
, try following
->whereIn("risk", $json->risks)
Read More
I have made some changes in your script :
$json = (object)Input::all();
$loans = DB::table("loans")
->where("years", ">=", $json->year_low)
->where("years", "<=", $json->year_high)
->whereIn("risk", array($json->risks))
->get();
This will work and you will get the array of values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With