Skip to content

PhpStorm Eloquent Helper Code "Property accessed via magic method" #205

@pxlrbt

Description

@pxlrbt

When generating the Eloquent Helper Code via Laravel Idea I always get warnings inside a model referencing the same models properties.

image

E.g.

The following code will highlight $this->name as "Property accessed via magic method"

class User {
    public function getName()
    {
        return $this->name;
    }
}

When accessing a property from outside the models scope it works fine. E.g. accessing ->name on role inside the User model is fine.

class User {
    public function getRoleName()
    {
        return Role::first()->name;
    }
}

Using laravel-ide-helper with php artisan ide-helper:models -M which generates a @mixin DocBlock also works.

/**
 * @mixin IdeHelperApplicant
 */
class User

Adding the DocBlock directly to the model also works, but is messing up the models code:

/**
 * @property string $name
 */
class User 

Maybe this in an issue with PhpStorm but it would be great to have a workaround (e.g. via the --write-mixin option)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions