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

::find and ::first not returning correct model #1609

Open
juliansteenbakker opened this issue Nov 5, 2024 · 2 comments
Open

::find and ::first not returning correct model #1609

juliansteenbakker opened this issue Nov 5, 2024 · 2 comments
Labels

Comments

@juliansteenbakker
Copy link

Versions:

  • ide-helper Version: 3.2.2
  • Laravel Version: 11.30.0
  • PHP Version: 8.3.x

Description:

::find returns Illuminate\Database\Eloquent\Collection|null|TModel
::first returns Illuminate\Database\Eloquent\TValue|null

image

@mfn
Copy link
Collaborator

mfn commented Nov 5, 2024

Probably because \Illuminate\Database\Eloquent\Builder::find transparently supports finding multiple models by their primary key

@pataar
Copy link
Contributor

pataar commented Nov 5, 2024

Actually, it's because generics aren't supported correctly. I tried to fix it on my fork, but it's a bit hard because of the forked phpdoc package that's included.

It should return a TModel, which is defined as template at the top of the Builder class:
image

Wat worked for me (it's far from ideal though), is replacing the @mixin \Eloquent for the @mixin Builder<$this> in each model phpdoc.

This gives the following result:
image

It can be done using this code snippet (requires the GNU sed version):

find app/Models -type f -name '*.php' -exec sed -i 's/@mixin Eloquent/@mixin \\Illuminate\\Database\\Eloquent\\Builder<\$this>/g' {} +
find app/Models -type f -name '*.php' -exec sed -i 's/@mixin \\Eloquent/@mixin \\Illuminate\\Database\\Eloquent\\Builder<\$this>/g' {} +

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants