Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get type of model when using Eloquent with methods from Query\Builder #1574

Open
pjio opened this issue Jul 27, 2024 · 0 comments
Open

Get type of model when using Eloquent with methods from Query\Builder #1574

pjio opened this issue Jul 27, 2024 · 0 comments

Comments

@pjio
Copy link
Contributor

pjio commented Jul 27, 2024

First thank you for this great package which helped me a lot!

Summary

For methods from Illuminate\Database\Query\Builder the generated return type is Illuminate\Database\Query\Builder. Therefore methods like whereNotNull() lose information about the model:

Screenshot-2024-07-27_13-02

For methods from Illuminate\Database\Eloquent\Builder the generated return type is Illuminate\Database\Eloquent\Builder|static. Therefore the result is a correctly typed model or collection (see: 378adeb)

It should be possible to use the methods with the same behavior:

Screenshot-2024-07-27_13-04

Roughly 122 methods are affected select() selectSub() selectRaw() fromSub() fromRaw() addSelect() distinct() from() useIndex() forceIndex() ignoreIndex() join() joinWhere() joinSub() joinLateral() leftJoinLateral() leftJoin() leftJoinWhere() leftJoinSub() rightJoin() rightJoinWhere() rightJoinSub() crossJoin() crossJoinSub() mergeWheres() whereColumn() orWhereColumn() whereRaw() orWhereRaw() whereIn() orWhereIn() whereNotIn() orWhereNotIn() whereIntegerInRaw() orWhereIntegerInRaw() whereIntegerNotInRaw() orWhereIntegerNotInRaw() whereNull() orWhereNull() whereNotNull() whereBetween() whereBetweenColumns() orWhereBetween() orWhereBetweenColumns() whereNotBetween() whereNotBetweenColumns() orWhereNotBetween() orWhereNotBetweenColumns() orWhereNotNull() whereDate() orWhereDate() whereTime() orWhereTime() whereDay() orWhereDay() whereMonth() orWhereMonth() whereYear() orWhereYear() whereNested() addNestedWhereQuery() whereExists() orWhereExists() whereNotExists() orWhereNotExists() addWhereExistsQuery() whereRowValues() orWhereRowValues() whereJsonContains() orWhereJsonContains() whereJsonDoesntContain() orWhereJsonDoesntContain() whereJsonContainsKey() orWhereJsonContainsKey() whereJsonDoesntContainKey() orWhereJsonDoesntContainKey() whereJsonLength() orWhereJsonLength() dynamicWhere() whereFullText() orWhereFullText() whereAll() orWhereAll() whereAny() orWhereAny() groupBy() groupByRaw() having() orHaving() havingNested() addNestedHavingQuery() havingNull() orHavingNull() havingNotNull() orHavingNotNull() havingBetween() havingRaw() orHavingRaw() orderBy() orderByDesc() inRandomOrder() orderByRaw() skip() offset() take() limit() forPage() forPageBeforeId() forPageAfterId() reorder() union() unionAll() lock() lockForUpdate() sharedLock() beforeQuery() setBindings() addBinding() mergeBindings() useWritePdo() dump() dumpRawSql()
pjio added a commit to pjio/laravel-ide-helper that referenced this issue Jul 27, 2024
pjio added a commit to pjio/laravel-ide-helper that referenced this issue Jul 27, 2024
pjio added a commit to pjio/laravel-ide-helper that referenced this issue Jul 27, 2024
pjio added a commit to pjio/laravel-ide-helper that referenced this issue Oct 29, 2024
pjio added a commit to pjio/laravel-ide-helper that referenced this issue Oct 29, 2024
pjio added a commit to pjio/laravel-ide-helper that referenced this issue Oct 29, 2024
barryvdh pushed a commit that referenced this issue Oct 31, 2024
)

* Add return type `|static` to Query\Builder methods (#1574)

* Replace return type Query\Builder with Eloquent\Builder (#1574)

* Replace return type Query\Builder only for facade Eloquent (#1574)

* Add special return type replacement for Macros of \Eloquent

* Restrict special return type to methods from Eloquent\Builder and Query\Builder

* Do not overwrite return type in normalizeReturn() with conditional call of setType()

* Use generic return type for builder methods in \Eloquent

* composer fix-style

---------

Co-authored-by: laravel-ide-helper <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant