1、需求是希望可以在整个分页的数组中插入 9 条数据,使分页有 10 条数据,可以显示两页。这样相当于在 time 在前 9 天都有数据,,这种情况要怎么插入数据到分页集合中呢。
获得 LengthAwarePaginator
对象以后 ,可以使用对象的 getCollection()
方法 获得 \Illuminate\Support\Collection
对象,此对象的 push , prepend 方法可以向分页里面追加数据。
2、需求是两个数组拼接,然后分页展示,通过foreach循环push , prepend 方法前后追加拼接,分页展示:
$lists = SourceModel::where($where)->whereNotIn('id', function ($query) use($user_id){ $query->select('s_id')->from('visit')->where('visit.user_id',$user_id); });; $lists = $lists ->whereIn('id',$rec_collect)->orderBy('visit_num','desc') ->select($fields)->paginate(10); if($lists->total() < 1