Placeholder with repeater

I'd want to display repeater values in layout placeholders. Is there a method to loop through repeaters and display their values in the summary section? (Proper list format) Code
Placeholder::make('Ingredients')
->content(function (Get $get) {
$ingredients = $get('menu_item_ingredients'); // Repeater
})->columnSpanFull()
Placeholder::make('Ingredients')
->content(function (Get $get) {
$ingredients = $get('menu_item_ingredients'); // Repeater
})->columnSpanFull()
10 Replies
waleedGRT
waleedGRTOP2y ago
No description
Patrick Boivin
What do you want to see under Ingredients? Can you give me an example of the output?
waleedGRT
waleedGRTOP2y ago
I want to iterate the repeater in the form of a list items
No description
Patrick Boivin
Like this?
Ingredients
- Lemon
- Coconut
Ingredients
- Lemon
- Coconut
waleedGRT
waleedGRTOP2y ago
Yes
Patrick Boivin
Something like this. You can adjust it to what you need:
Placeholder::make('Ingredients')
->content(function (Get $get) {
$items = collect($get('menu_item_ingredients') ?: [])
->map(fn ($item) => "<li>{$item['name']}</li>")
->join();

return new HtmlString("<ul>$items</ul>");
})
// ...
Placeholder::make('Ingredients')
->content(function (Get $get) {
$items = collect($get('menu_item_ingredients') ?: [])
->map(fn ($item) => "<li>{$item['name']}</li>")
->join();

return new HtmlString("<ul>$items</ul>");
})
// ...
waleedGRT
waleedGRTOP2y ago
Working perfectly, but it constitutes a major security risk⚠️
No description
Patrick Boivin
Obviously I don't know anything about your app, who uses this form, etc. I can't comment on what's really secure or not.
"<li>" . htmlentities($item['name']) . "</li>"
"<li>" . htmlentities($item['name']) . "</li>"
I think you know what you're doing at this point 😜
waleedGRT
waleedGRTOP2y ago
I shared it because someone else could utilize it in the future, nevertheless I sincerely appreciate your help.
Patrick Boivin
You make a good point, and actually I think this may be stretching the Placeholder a bit. I think a View component (to render a real Blade view) may be a better fit for this use case. There would be no need for string concatenation and the content would be escaped by default.

Did you find this page helpful?