[英]Laravel DB mysql select where column exists in array?
我发送一个数组到我在Laravel 5中制作的API,这是一个允许值的数组ex: [1,3,5]
我尝试做这样的选择:
$json = (object)Input::all();
$loans = DB::table("loans")
->where("years", ">=", $json->year_low)
->where("years", "<=", $json->year_high)
->where("risk", $json->risks)
->get();
risks
就是数组。
我从数据库收到的是空数组。
在测试中,我发送每个可能的值0 ... 4但我收到一个空数组。
如何在数组中选择列值存在的行?
我在你的脚本中做了一些更改:
$json = (object)Input::all();
$loans = DB::table("loans")
->where("years", ">=", $json->year_low)
->where("years", "<=", $json->year_high)
->whereIn("risk", array($json->risks))
->get();
这将有效,您将获得值数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.