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

laravel-ide-helper broken with laravel 11 #2959

Open
Nemesis19 opened this issue Jul 24, 2024 · 15 comments
Open

laravel-ide-helper broken with laravel 11 #2959

Nemesis19 opened this issue Jul 24, 2024 · 15 comments
Labels

Comments

@Nemesis19
Copy link

Nemesis19 commented Jul 24, 2024

Describe the bug
Last versions of Intelephense are showing errors on model instances. See the screenshot.
Screenshot 2024-07-24 alle 21 34 20

With error
Expected type 'App\Models\Vehicle'. Found 'Illuminate\Database\Eloquent\TModel'.intelephense(P1006)
@var \Illuminate\Database\Eloquent\TModel $vehicle

and for $section this is the error
Expected type 'App\Models\Section'. Found 'Illuminate\Database\Eloquent\Builder|null'.intelephense(P1006)
@var \Illuminate\Database\Eloquent\Builder|null $section

The only way to solve it is to put @var annotations like these (and not convenient to be added everywhere)

/** @var Vehicle|null $vehicle **/ /** @var Section|null $section **/ VehicleService::startWithSection($vehicle, $section);

it doesn't seem a problem many people have, so is there any configuration that it's causing this?

Thanks

@bmewburn
Copy link
Owner

bmewburn commented Jul 24, 2024

It seems the template type TModel is not resolving to the actual type. To understand why, some more context is needed.
What version of intelephense is this?
What version of Laravel?
Are you using https://github.com/barryvdh/laravel-ide-helper? If so, are you generating model docs?

@Nemesis19
Copy link
Author

Nemesis19 commented Jul 24, 2024 via email

@bmewburn
Copy link
Owner

Latest intelephense version as in the pre-release (1.11) ? Or 1.10.4? When generating model docs is it to a separate file or the actual model file?

@bmewburn
Copy link
Owner

Could be related to barryvdh/laravel-ide-helper#1572, laravel/framework#51851

@Nemesis19
Copy link
Author

Nemesis19 commented Jul 25, 2024

I'm sorry I didn't specify...latest stable v1.10.4. The models are generating inside the Model file.
Thanks for pointing me to the right direction. I do agree the problems are probably related!

@bmewburn bmewburn changed the title Found 'Illuminate\Database\Eloquent\TModel'. laravel-ide-helper broken with laravel 11 Jul 25, 2024
@bmewburn bmewburn pinned this issue Jul 25, 2024
@sebj54
Copy link

sebj54 commented Jul 31, 2024

I don't know if it is related but I had a similar problem after upgrading some packages. Laravel was already updated to 11, so I think it works correctly with Laravel 11.

The problem is that the more you install vendor packages, the more you are likely to exceed the maximum file size.

To check if it you have the same problem, go to ViewOutput → select intelephense in the dropdown. You should see this error:

[Warn  - 16:10:12] file:///Users/myuser/projects/myproject/_ide_helper.php is over the maximum file size of 1000000 bytes.

I increased the limit in the settings and it now works as expected!

@Nemesis19
Copy link
Author

I don't know if it is related but I had a similar problem after upgrading some packages. Laravel was already updated to 11, so I think it works correctly with Laravel 11.

The problem is that the more you install vendor packages, the more you are likely to exceed the maximum file size.

To check if it you have the same problem, go to ViewOutput → select intelephense in the dropdown. You should see this error:

[Warn  - 16:10:12] file:///Users/myuser/projects/myproject/_ide_helper.php is over the maximum file size of 1000000 bytes.

I increased the limit in the settings and it now works as expected!

Non this is not my case unfortunately.

@tlevi101
Copy link

@bmewburn

It seems the template type TModel is not resolving to the actual type. To understand why, some more context is needed. What version of intelephense is this? What version of Laravel? Are you using https://github.com/barryvdh/laravel-ide-helper? If so, are you generating model docs?

I have the same issue.

Laravel version: 11.21
Inteliphense version: 1.12.6
Ide helper version: 3.1

IDE helper generates doc comments for Illuminate\Database\Eloquent\Model:

/**
 * 
 *
 * @mixin \Eloquent
 * @mixin \Illuminate\Database\Eloquent\Builder
 * @mixin \Illuminate\Database\Query\Builder
 */
abstract class Model ...

And Illuminate\Database\Eloquent\Builder has a template PHPDoc tag by default:

/**
 * @template TModel of \Illuminate\Database\Eloquent\Model
 * ...
 */
class Builder ...

The main problem is that the correct type isn't being passed down to the Builder class. I tried adding a generic PHPDoc to my model like this:

/**
 * @mixin \Illuminate\Database\Eloquent\Builder<\App\Models\MyModel>
 */
class MyModel ...

Unfortunately, this didn’t work with Intelephense. However, I believe this could be a possible solution because it works with another php intelisense.

@bmewburn
Copy link
Owner

@tlevi101 @mixin is available with the premium version.

@tlevi101
Copy link

@tlevi101 @mixin is available with the premium version.

I do have premium, and everything else works with @mixin.

@bmewburn
Copy link
Owner

bmewburn commented Sep 17, 2024

@tlevi101 \Illuminate\Database\Eloquent\Builder doesn't have static methods. The ide_helper generated Eloquent class declares the builder methods as static. I don't think it's the right solution to presume all mixin class functions are static.

I generated a helper file with laravel 11 and fixed it manually below (untested). Ideally the laravel-ide-helper maintainers will fix it. https://gist.github.com/bmewburn/0433032378015d3cfefae0baf872bcdd

Even though laravel 11 broke ide_helper it did improve the builder types in laravel itself. You can call MyModel::query() and get an instance of \Illuminate\Database\Eloquent\Builder<MyModel> which then gives access to all fluent builder methods while templated to the model class.

@engaboud
Copy link

لقد قمت بإنشاء ملف مساعد باستخدام laravel 11 وقمت بإصلاحه يدويًا أدناه (لم يتم اختباره). من الناحية المثالية، سيقوم المشرفون على laravel-ide-helper بإصلاحه. https://gist.github.com/bmewburn/0433032378015d3cfefae0baf872bcdd

@KentarouTakeda
Copy link

This issue has been fixed by barryvdh/laravel-ide-helper#1591.
By updating Laravel IDE Helper to 3.2, you will be able to correctly extract model types.

@bmewburn
Copy link
Owner

Thanks @KentarouTakeda ! That fixed part of the problem but I think the file created with php artisan ide-helper:generate is still broken as it doesn't handle templates or conditional return types.

@chack1172
Copy link

@bmewburn it will be fixed by barryvdh/laravel-ide-helper#1631

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

7 participants