为什么在分页时我得到了不同的变量类型? (Laravel)

huangapple go评论57阅读模式
英文:

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

为什么在分页时我得到了不同的变量类型? (Laravel)

  • rest of pages items->items is associative array

为什么在分页时我得到了不同的变量类型? (Laravel)

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)

huangapple
  • 本文由 发表于 2023年4月6日 23:31:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75951261.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定