bmewburn / vscode-intelephense

PHP intellisense for Visual Studio Code
https://intelephense.com
Other
1.56k stars 92 forks source link

Undefined method/property for models extends from Eloquent #2898

Closed yanghoxom closed 3 weeks ago

yanghoxom commented 3 weeks ago

Describe the bug if I extend from Eloquent for a model, I will have some method/property that can not "look up" by this extension and show error

I'm not sure if this issue is related to the premium feature mixin or not I don't have license ide-helper auto-add @mixin Eloquent to PHPDOC but even if I remove that line, the error still continues to show

The error is fixed if I switch to extends Model as usual. but to be honest, most of the project is extending Eloquent, I don't want to change the whole project just to fix extension related display errors

To Reproduce

use Eloquent;
/**
doc
*/
final class Book extends Eloquent
{...}

this thing will show errors

final class Book extends Eloquent
Undefined type 'Eloquent'.

$this->hasMany...
Undefined method 'hasMany'.
Undefined method 'belongsTo'.

$book->exists
Undefined property '$exists'.

Expected behavior It shouldn't show any error because my code working well

Screenshots image image

Platform and version PHP intelephense 1.10.4 vscode 1.87.2

bmewburn commented 3 weeks ago

@mixin is supported in premium only. Eloquent is generated by the ide_helper package. If it is not found then it must not be in your workspace.

yanghoxom commented 3 weeks ago

@bmewburn but I already import by use Eloquent, Doesn't it have any effect?

bmewburn commented 3 weeks ago

The file that declares Eloquent must not be in your workspace or is not indexed for some reason.

yanghoxom commented 3 weeks ago

@bmewburn I added a license, I can use premium features. image 2024-06-09_21-00-10

but errors related to extends Eloquent still remaining FYI this is a file sample

<?php
declare(strict_types=1);
namespace App\Models;

use Eloquent;

/**
...
 * @mixin Eloquent
*/

final class Book extends Eloquent
{
....
    public function attachments(): HasMany
    {
        return $this->hasMany(BookAttachment::class);
    }
...
}

->hasMany throw Undefined method extends Eloquent throw Undefined type

bmewburn commented 3 weeks ago

Where is the file that declares Eloquent?

yanghoxom commented 3 weeks ago

@bmewburn it is an extra class it comes from ide-helper.php https://github.com/barryvdh/laravel-ide-helper/blob/master/config/ide-helper.php#L183 image

bmewburn commented 3 weeks ago

Right, so where is that file in your workspace?

yanghoxom commented 3 weeks ago

@bmewburn Thank you, you are right I forgot to run php artisan ide-helper:generate to create _ide_helper.php everything is OK right now