plugin icon indicating copy to clipboard operation
plugin copied to clipboard

Add support for Livewire's "Computed Properties"

Open smares opened this issue 4 years ago • 5 comments

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.

smares avatar Aug 05 '21 11:08 smares

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?

adelf avatar Aug 05 '21 11:08 adelf

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.

smares avatar Aug 05 '21 20:08 smares

I'll try to make it working without phpDoc comment

adelf avatar Aug 05 '21 20:08 adelf

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

/**
 * @property-read bool $shouldShowBudget
 */
class MyComponent extends Component {}

Francismori7 avatar Dec 01 '21 16:12 Francismori7

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() { ... }

mityukov avatar Mar 27 '24 09:03 mityukov