英文:
Why i got diffrent variables types using pagination? (Laravel)
问题
I have weird problem, i got 2 different types of returning data from pagination:
- first page items->items is numeric array
- rest of pages items->items is associative array
Why is this happening, here is code
$models = Model::withTranslation()->with(['relation' => function ($relation) {
$relation->withTranslation();
}])->get();
return $models->paginate(self::PER_PAGE);
relation is one to one, translation package is link to the package, self::PER_PAGE = 10.
英文:
I have weird problem, i got 2 different types of returning data from pagination:
- first page items->items is numeric array
- rest of pages items->items is associative array
Why is this happening, here is code
$models = Model::withTranslation()->with(['relation' => function ($relation) {
$relation->withTranslation();
}
}])->get();
return $models->paginate(self::PER_PAGE);
relation is one to one, translation package is https://docs.astrotomic.info/laravel-translatable, self::PER_PAGE = 10
答案1
得分: 1
我刚刚找到了原因,但我仍然发布了问题,也许有人能节省一些时间。我刚刚将这个修改:
->get()->paginate(10)
更改为这个:
->paginate(10)
英文:
I just find out the reason, but I still posted the problem, maybe someone would save some time. I just changed this:
->get()->paginate(10)
to this:
->paginate(10)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论