0

I have a blade component which can be used in blade files.

<x-my-component :inputOne="Hello" : inputTwo="Hi again"></x-my-component>

And for legacy reasons I would like to compile/translate it into html string so I could be used like that

$htmlComponentCode = Blade::compileComponent(
    '<x-my-component :inputOne="Hello" : inputTwo="Hi again"></x-my-component>'
);

echo htmlComponentCode ;

And by echoing it out it will display the component same as it was included in a blade file.

I'm aware of this solution:

$html = (new MyComponent("Hello", "Hi again"))->render();

But I would prefer the on with html name.

Is something like that possible?

Marek Barta
  • 344
  • 1
  • 4
  • 17
  • Doesn't look like it would be easy. Similar question here: https://stackoverflow.com/questions/61484068/render-laravel-7-component-programmatically – miken32 Jan 13 '21 at 18:16

1 Answers1

1

Since this question is inactive for quite some time I will close it concluding there is probably no better solution than

$html = (new MyComponent("Hello", "Hi again"))->render();
Marek Barta
  • 344
  • 1
  • 4
  • 17