Prido's avatar
Level 2

dynamic blade

is it possible to load blade components from db, or to create components and save as blade then load these components following preferences saved in db, for example i allow user to choose a card design for the to see wen they login, then the system has to pick that card and populate it dynamically, so these components should be sort of looped and populated to construct a full page to the end, am stuck here please help out

0 likes
7 replies
Prido's avatar
Level 2

thanks is it possible to pass data to these components or to also pass objects

rodrigo.pedra's avatar

Sure, just don't forget to use add colons (:) before dynamic props as you would do with regular components.

Prido's avatar
Level 2

thanks for your responses i think let me use the @component , no am thinking if i have an array like so $data = ['componentName'=>'compname','numberOfPosts'=>10,'title'=>'featuredItems','category'=>'fruits'].. now i have to pass $data to the component then fetch where category is fruits limit to 10 then put the component title as featuredItems.... would you mind showing me a snipset on the component side after receiving $data

rodrigo.pedra's avatar
Level 56
@php
$componentName = Arr::get($data, 'componentName');
$props =  Arr::except($data, 'componentName');
@endphp

<x-dynamic-component :component="$componentName" :props="$props" />

The in your component's class you can accept a props array in its constructor and manipulate the business logic you need in that class.

2 likes

Please or to participate in this conversation.