#Blade Component Intellisense for e.g. props
11 messages · Page 1 of 1 (latest)
Is that data that your passing from controller or what? @lavish imp
No, for example <x-post-card :post="$post" /> and my "post card" component theoretically might do {{ $post->title }} and access other post attributes
I'd like to define the type of the props in the component (@props(['post'])) somehow so i get intellisense, linting, etc in the template
otherwise i can just type {{ $post->this_doesnt_exist }} (or a typo like {{ $post->titel }}) with zero linting errors or anything. itll just be an empty string on the page at runtime, or potentially some error depending on the actual shape
Ooh, okay. I think you talking about autocomplete feature. Since it related to the attributes of model, you can try Laravel Idea (paid) or Laravel IDE helper(free) to accomplish that.
Or you might want to use Data Transfer Object(manually listing the attributes of your model) or by using Spatie Data package(free).
Or your should install some extensions or plugins in your code editor.
Using Laravel Idea. I think the root issue is that I'm not defining what type/shape the props are anywhere in Blade, so I assume you can't
In other words, how would the IDE have any idea what the props are if I'm not defining them?
Even smart IDE like phpstorm struggle to get the attributes of model.
@lavish imp attributes from models are not actually present as properties, that's why your IDE has no idea. It uses the magic method __get under the hood to fetch the attributes. You can get intellisense by adding docblocks, or using something like "laravel-ide-helper" to generate those for you.
For component attributes, not really much to do