【发布时间】:2021-06-23 04:40:03
【问题描述】:
在我的 Laravel 项目中,用户可以通过前端 GUI 从表中查找数据,该 GUI 允许他们选择表和列(有限制)。我正在尝试在名为event_action 的列上的 where 子句中搜索多个不同的值,以便我可以带回多个结果,我似乎得到了某种结果,但我没有看到我的所有结果?
$results = DB::table('my_table')
->select('event_category', 'event_action', 'event_count', 'created_at')
->where([
['event_category', 'my category'],
['event_action', ['value1', 'value2']],
['created_at', '>=', '2021-03-01']
])
->get();
我的event_action 列有很多行,其中一些行的值有value1,而其他行的值有value2,但在我返回的结果中,我只看到一个或另一个,而不是两者,例如,在修补匠:
=> Illuminate\Support\Collection {#3501
all: [
{#3433
+"event_category": "my category",
+"event_action": "value2",
+"event_count": "16",
+"created_at": "2021-03-01 01:00:03",
},
{#3499
+"event_category": "my category",
+"event_action": "value2",
+"event_count": "16",
+"created_at": "2021-03-01 01:15:06",
},
{#3464
+"event_category": "my category",
+"event_action": "value2",
+"event_count": "19",
+"created_at": "2021-03-01 01:30:05",
},
{#3465
+"event_category": "my category",
+"event_action": "value2",
+"event_count": "21",
+"created_at": "2021-03-01 01:45:07",
},
{#3466
+"event_category": "my category",
+"event_action": "value2",
+"event_count": "24",
+"created_at": "2021-03-01 02:00:05",
},
],
}
【问题讨论】:
-
什么意思?就像我搜索“r”并重新运行该列中包含 r 的任何内容?
-
好吧,我应该看到包含
value2和value1的结果,因为我的数据库中有一些行的列值包含value2,而另一些包含value1,为什么我只会回来value2吗? -
也许可以试试 orWhere,如果用户可以搜索多个值添加一个循环