Code Vision: No Usage shown for Laravel Custom Attributes

I'm using the latest version of PhpStorm (2022.3.1) with the new Code Vision and Laravel 9+.

Problem: No Usage shown for Laravel Custom Attributes


This is not a huge issue, but rather an eyesore.

 

When I use a Model to create a custom Attribute like this:

    public function getFormattedStartDateAttribute(): string
    {
        if (!$this->start_date) {
            return 'TBD';
        } else {
            return $this->start_date->format('M. d, Y');
        }
    }

And then use it in the View like this or this:

  • Date {{ $event->formattedStartDate }}
  • Date {{ $event->formatted_start_date }}

There is no usage record in the Model.

 

If I do this method:

public function isGuest(): bool
{
return $this->participant_parent_id !== null;
}

And then in the View:

{{ $participant->isGuest() }}

The usage is shown.

Is there a way to fix this so PhpStorm recognizes the Laravel Custom Attributes?

0
3 comments

Hey,

Could you please check if "Find usages" (apart from Code Vision) works fine in this case? 

0

"Find usages" works great. I click on it and it will tell me everywhere that method is being used.

I should note that when using Laravel you can call the custom attributes like this:

public function getFormattedStartDateAttribute():

// Laravel recommends calling like this: (Option 1 & 2)
Option 1. (camelCase/drop the get and Attribute) {{ $event->formattedStartDate }} // Shows No Usage Data
Option 2. (snake_case/drop the get and Attribute) {{ $event->formatted_start_date }} // Shows No Usage Data

// This below Option 3 does show the usage data, but goes against the Laravel format.
Option 3. (camelCase/Use full method name) {{ $event->getFormattedStartDateAttribute() }} // Shows Usage Data!

 

0

Please sign in to leave a comment.