php - WhereIn Eloquent 形式

标签 php laravel orm eloquent

我有两个数组

temp[]
time[]

例如,如果我的数组中有这样的数据

    temp   time 
[0]  80     45
[1]  70     50
[2]  85     65
[3]  90     30 

我想根据这两个数组参数查询数据 像 (select * from MyTable where (temperature = 80 and time = 45 ))for the next (select * from MyTable where (temperature = 70 and time = 50 )) 等等

我正在做这样的事情

 $mix=MyTable::whereIN('temperature', $temp)
         ->whereIN('time', $time)->where('category',$cat)
         ->get();

但它给我的输出是这两个参数的组合。不完全是从数组 0 开始...

我希望我能正确解释我的问题..

我试过了..

    $result=Ergebnisse::where('name_id', $nam)->where('geometrie_id', $geo)->get();
    foreach ($result as $key => $res) {

$mix=Ergebnisse::where('temperatur', $res->temperatur)
         ->where('zeit', $res->zeit)->groupBy('katogorie_id')
         ->get();

}

当我 dd($mix) 它只显示一个结果。但根据我的数据库,它应该显示不止一个

最佳答案

whereIn() 在这里不起作用。做这样的事情:

$data = MyTable::where('category', $cat)
    ->where(function($q) use($array) {               
        foreach ($array as $item) {
             $q->orWhere(function($q) use($item) {
                 $q->where('temperature', $item['temp'])
                   ->where('time', $item['time']);
            }
        }
    })->get();

关于php - WhereIn Eloquent 形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43093466/

相关文章:

php - Doctrine 2 中的动态表/实体名称

php - laravel Eloquent : Eloquent relation needs to return something when there is no data instead of returning null object

php - 这个上下文的流程应该如何? (根据选择的付款方式,将处理付款的代码放在哪里?)

java - 三路 hibernate ORM 映射 - 如何?

symfony - APC 不保存 fosuserbundle 扩展类中的属性

php - WordPress - 向定制器添加第二个 Logo

php - 当我使用 get_query_var 时看到的随机字符串是什么?

php - 使用 PHP 从 Apache 服务器运行 Python 脚本

php - 如何从图像结果列表中选择一张图像?

ruby-on-rails - Rails 关联范围中左连接的子查询