laravel-idea / plugin

Laravel Idea plugin for PhpStorm
https://laravel-idea.com/
161 stars 7 forks source link

Add support for Livewire's "Computed Properties" #354

Open smares opened 2 years ago

smares commented 2 years ago

Sorry for hijacking https://github.com/laravel-idea/plugin/issues/353#issuecomment-893249453, thought it was related.

Would be awesome if Laravel Idea would support Livewire's computed properties (https://laravel-livewire.com/docs/2.x/properties#computed-properties) that work in a similar way to accessors where you define a public method getFooBarProperty which you can then access in the component Blade file using $this->fooBar. With support, I mean clicking on fooBar in the template would jump to getFooBarProperty.

adelf commented 2 years ago

It will be possible after the big 5.0 update. For now... What if I just teach PhpStorm that $this in the blade file is a ShowPost class object?

smares commented 2 years ago

I already have a PHP comment in my Blade file containing /** @var App\Http\Livewire\Component $this */ but it doesn't work for computed properties because there is no $fooBar declared in the component. It hints getFooBarProperty() and all other public properties and methods, though.

adelf commented 2 years ago

I'll try to make it working without phpDoc comment

Francismori7 commented 2 years ago

For people wondering, this is how I do it in the mean-time:

/**
 * @property-read bool $shouldShowBudget
 */
class MyComponent extends Component {}
mityukov commented 3 months ago

An update here: Livewire now also supports computed properties via php attributes:

    // old way:
    protected function getProjectsProperty() { ... }

    // Livewire 3's way:
    #[\Livewire\Attributes\Computed]
    protected function projects() { ... }