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
waleedGRTOP15mo ago
No description
Patrick Boivin
Patrick Boivin15mo ago
What do you want to see under Ingredients? Can you give me an example of the output?
waleedGRT
waleedGRTOP15mo ago
I want to iterate the repeater in the form of a list items
No description
Patrick Boivin
Patrick Boivin15mo ago
Like this?
Ingredients
- Lemon
- Coconut
Ingredients
- Lemon
- Coconut
waleedGRT
waleedGRTOP15mo ago
Yes
Patrick Boivin
Patrick Boivin15mo ago
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
waleedGRTOP15mo ago
Working perfectly, but it constitutes a major security risk⚠️
No description
Patrick Boivin
Patrick Boivin15mo ago
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
waleedGRTOP15mo ago
I shared it because someone else could utilize it in the future, nevertheless I sincerely appreciate your help.
Patrick Boivin
Patrick Boivin15mo ago
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.
Want results from more Discord servers?
Add your server