#Blade Component Intellisense for e.g. props

11 messages · Page 1 of 1 (latest)

lavish imp
#

Is there no way to declare the type of each prop in a Blade component to get e.g. intellisense and linting? I can't seem to find an answer or people discussing this.

mellow sky
#

Is that data that your passing from controller or what? @lavish imp

lavish imp
#

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

mellow sky
#

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.

lavish imp
#

In other words, how would the IDE have any idea what the props are if I'm not defining them?

mellow sky
#

Even smart IDE like phpstorm struggle to get the attributes of model.

tepid solstice
#

@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