我正在尝试开发一个准则(Andersao Repository Library),以获取一些按升序排列的记录,然后将该记录合并为其余记录。我在该表中有一个id字段,我想要实现的是从一个数字到末尾(以7 o 13为例)获取所有记录,然后在同一查询中获取其余记录(也许使用union)。
结果必须类似于:
[
4 => 6
5 => 7
6 => 9
7 => 10
8 => 12
9 => 13
10 => 0
11 => 1
12 => 2
13 => 3
14 => 4
15 => 5
]
我正在尝试:
public function apply($model,RepositoryInterface $repository)
{
$clonedmodel = clone $model;
$model = $model->where('id','>=',$this->id);
if ($this->order == 0) {
$clonedmodel == $clonedmodel->where('id','<',$this->id);
}
$model = $model->union($clonedmodel);
return $model;
}
但是在此查询中,联合会再次获取所有记录。你能给我指出一个解决方案吗?谢谢!
注意:我可以使用查询生成器来翻译没有库的任何解决方案。