【发布时间】:2021-12-31 22:46:07
【问题描述】:
我有一张表,用于获取输入数据的数据组合。比如多个分子(化学组合)作为一个组合。
输入
$id = $required->input('search'); // array:2 [ 0 => "3" 1 => "8"]
案例 1:
表 1
| id | refid | product_id | name | ref_2 |
|---|---|---|---|---|
| 1 | 1,3,46,7 | 5 | test | 6 |
| 2 | 1,3,8,90 | 10 | test1 | 8 |
| 3 | 3,8,67 | 14 | test 4 | 11 |
| 4 | 8,699, | 19 | test 4 | 11 |
查询
$model=Model::whereIn('ref_id',$id)->pluck('product_id');
Fetch Product,组合查询包含id的3,8
但它正在获取 id 的包含 3 或 8
案例 2
表 2
| id | refid | product_id | name | ref_2 |
|---|---|---|---|---|
| 1 | 3 | 5 | test | 6 |
| 2 | 5 | 10 | test1 | 8 |
| 3 | 8 | 5 | test 4 | 11 |
| 4 | 6 | 19 | test 4 | 11 |
$model = Model::whereIn('ref_id', $id)->groupBy('product_id')->pluck('product_id');
这可能吗?有更好的方法吗?
【问题讨论】: