【发布时间】:2020-01-05 11:30:58
【问题描述】:
当 id 数组与客户表中的 id 匹配时,我想从数据库中获取记录。
这是我的 ID 数组:
0 => 1
1 => 1788
2 => 887
3 => 697
4 => 719
我有以下查询,
$customers = Customer::whereIn('id', $idArray)->get();
我得到了我需要的所有客户,但顺序不正确。我正在按以下顺序吸引客户。
1
697
719
887
1788
这是默认行为还是我做错了什么。
感谢任何建议。
【问题讨论】:
-
不能加
orderBy吗? -
@Jonnix 我希望客户在数组中的顺序相同
-
对了,顺序规则是什么?只是 $idArray 的顺序? stackoverflow.com/questions/8322849/… 有帮助吗?我不知道这在 Laravel 中会如何翻译。
-
@Jonnix 是 id 数组的顺序
标签: php laravel eloquent where-clause