Skip to content

add generic return types to Builder paginate methods#60045

Open
levikl wants to merge 1 commit intolaravel:13.xfrom
levikl:add-generic-return-types-to-builder-paginate-methods
Open

add generic return types to Builder paginate methods#60045
levikl wants to merge 1 commit intolaravel:13.xfrom
levikl:add-generic-return-types-to-builder-paginate-methods

Conversation

@levikl
Copy link
Copy Markdown

@levikl levikl commented May 8, 2026

summary

Illuminate\Database\Eloquent\Builder already declares @template TModel of \Illuminate\Database\Eloquent\Model at the class level, and the three paginator classes (LengthAwarePaginator, Paginator, CursorPaginator) already declare @template TKey of array-key and @template-covariant TValue. this change threads the two together by adding generic return type annotations to the three paginate methods on Builder.

before:

/** @return \Illuminate\Pagination\LengthAwarePaginator */
public function paginate(...) { ... }

/** @return \Illuminate\Contracts\Pagination\Paginator */
public function simplePaginate(...) { ... }

/** @return \Illuminate\Contracts\Pagination\CursorPaginator */
public function cursorPaginate(...) { ... }

after:

/** @return \Illuminate\Pagination\LengthAwarePaginator<int, TModel> */
public function paginate(...) { ... }

/** @return \Illuminate\Pagination\Paginator<int, TModel> */
public function simplePaginate(...) { ... }

/** @return \Illuminate\Pagination\CursorPaginator<int, TModel> */
public function cursorPaginate(...) { ... }

why

without these annotations, static analysis tools have no way to carry the model type through a paginator. a call like Product::paginate(5) resolves to an untyped LengthAwarePaginator, so tools that inspect the return shape (eg. for Inertia type generation) fall back to data: Record<string, unknown> instead of emitting data: Product[].

this is a docblock-only change; no runtime behavior is affected.

related

merge order

this -> laravel/surveyor -> laravel/wayfinder

@levikl
Copy link
Copy Markdown
Author

levikl commented May 8, 2026

asking for a friend: how do you backport a docblock change to laravel 12.x + 11.x?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant