plugin icon indicating copy to clipboard operation
plugin copied to clipboard

[Bug]: Model properties in model event listener closures are not detected properly

Open FeBe95 opened this issue 5 months ago • 2 comments

Bug description

When using model event listener closures, model properties are not detected properly. Code navigation is not working.

Plugin version

11.0.0.251

Operating system

Windows

Steps to reproduce

  1. Make sure that the helper code is up-to-date by running "Generate Helper Code"
  2. Add the following code (model event listener closure) to any model, e.g. \App\Models\User:
    protected static function boot(): void
    {
        parent::boot();
    
        static::updated(function (User $user) {
            echo $user->email;
            echo $user->wasChanged('email');
        });
    }
    
  3. Try to use code navigation ("Go To" → "Declaration or Usages") for the email property on $user->email

Result

PhpStorm displays "Cannot find declaration to go to"

Image

Notes

  • Model type and property type are detected correctly (see screenshots below)
  • Model property suggestion does list the email property (see screen recording below)
  • Code navigation is working for the email string on $user->wasChanged('email') (see screen recording below)
  • The actual implementation of a model event listener closure does not make a difference (e.g. using static):
    self::updated(static function (User $user) { /* ... */ }
    
    instead of
    static::updated(function (User $user) { /* ... */ }
    

Screenshots

Image Image

Screen recording

https://github.com/user-attachments/assets/422ed168-94b7-40d3-9f1b-3aaddd193c41

Relevant log output


FeBe95 avatar Jul 30 '25 14:07 FeBe95

It's a known issue. PhpStorm doesn't try to find any other User class implementation if it is already in this file. This code will work correctly in any other file.

We make it working for $this-> calls. I'll try to find a workaround for this case also.

adelf avatar Jul 31 '25 22:07 adelf

Oh, that makes sense. I'm looking forward to a possible workaround!

FeBe95 avatar Aug 01 '25 11:08 FeBe95