Passing props from x-dynamic-component to blade file #51921
-
Hello Laravel community, I have a question that I would like to dig into with your help, if possible. I'll detail my use case: {{-- top-menu.blade.php -- }}
@props(['buttonUrl'])
{{ $buttonUrl }} I want to read a component from my database (stored as an array) and display it, like so: @php
$block = [
"component" => "top-menu",
"props" => [
"buttonUrl" => "#",
],
];
@endphp
<x-dynamic-component
:component="$block['component']"
:props="$block['props']"
/> Of course :props doesn't work. This works fine with: @component($block['component'], $block['props'])
@endcomponent But @component is deprecated. Any way I can approach this with x-dynamic-component? I would like to keep the @props([]) array in the file, as I use it to parse the blade file and store the props in the database. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I think I solved it, won't delete it because it may help other people. Feel free to delete! <x-dynamic-component :component="$component" :attributes="new Illuminate\View\ComponentAttributeBag($props)" /> Instead of passing :props, you must pass :attributes by initiating a new ComponentAttributeBag. Thank you everyone! |
Beta Was this translation helpful? Give feedback.
I think I solved it, won't delete it because it may help other people. Feel free to delete!
Instead of passing :props, you must pass :attributes by initiating a new ComponentAttributeBag. Thank you everyone!