-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Compatible with Generics Eloquent Builder in Laravel 11.15 #1591
Compatible with Generics Eloquent Builder in Laravel 11.15 #1591
Conversation
What about adding the |
0a0bd35
to
2bbdfae
Compare
Good job @KentarouTakeda ! Would be awesome if this get merged. |
2bbdfae
to
bea576f
Compare
Thank you for your opinion. I deleted the Test failure is a separate issue. |
#1593 was closed because there was a mistake in the way it was modified. |
@barryvdh It can't parse complex generics or closures. The cause is probably this: I'm not sure how to fix it, so could you please look at the fix in this pull request first? |
To properly fix the failing tests, We needed to fix not only this repository but also barryvdh/ReflectionDocBlock.I've created a fix for: Could you please review this as well? |
Thank you very much for merging and publishing the RC version. For testing: $ composer require --dev -w barryvdh/laravel-ide-helper:v3.2.0-rc1 I used the RC version in two real world projects and confirmed that:
It seems to work fine for me. |
Plausible error/conflict with "smart-reset" option ( |
Thank you for the report. I reproduced it in my environment as well. I'll look into it. |
@KentarouTakeda @barryvdh I have a small question, was the drop of PHP 8.1 intended? The question is because I didn't read about it in the changelog 😄 |
@tvbeek Since Eloquent Builder's generics support was added in Laravel 11.15, the IDE Helper also requires that version of Laravel be at least that version. Laravel 11 requires php-8.2 or higher. |
Yes, the current version will keep working for older versions though |
|
Oh wait it does:
Which seems good enought, right? Laravel 11 is PHP8.2+ anyways, but 3.1.x keeps working on Laravel 10 and below and is possible to receive bugfixes if really required. |
I understand that there is a moment to drop PHP 8.1 (I have a project that is running on 8.1 that is why I found it) But I did suspect to see it in the changelog, that did me question if it was intended or not. 😃 |
Yeah I've updated the Release tab nog https://github.com/barryvdh/laravel-ide-helper/releases/tag/v3.2.0 |
Summary
Resolves #1572
When using Laravel IDE Helper with Laravel 11.15 or higher, the return type of model retrieval methods such as
$builder->get()
and$builder->find()
becomesModel
, which is more inconvenient than not using IDE Helper.This pull request will fix that.
Laravel 11.15 introduced breaking changes to generic types in DocBlocks. Therefore, in order to fix this, we need to pin the Laravel version that IDE Helper supports to 11.15 or higher. (There are ways to avoid this, but I don't recommend it because there are non-negligible tradeoffs.)
Type of change
Checklist
Detail
The reported issue was the lack of type information for model retrieval methods such as
find($id)
, but the cause was the type of the EloquentBuilder
that returned it.Laravel 11.15 has the following improvements:
Builder
accepts generic type parametersHowever, our tool defines a plain
Builder
with no type parameters as the return type forModel::query()
and magic where methods. Intellephense and PHPStan read this information.As a result, most model retrieval methods were missing return type information. This can be resolved by explicitly specifying a concrete model as the type parameter, which is always
static
.So the fix boils down to the following code: