How to customize the label for options in CheckboxList?
Right now I am getting the options for ChecboxList like:
and it works.
But I need to do custom made each option that can use HTML code, for example:
How to do that?
5 Replies
Can I somehow run/encapsulate this part:
via some map function or something before giving it to options()?
Has anybody done that or something else that is going to give me the final altered html result for each label/option of the checklist?
I am getting this error:
array_map(): Argument #2 ($array) must be of type array, Illuminate\Support\Collection given
when trying
Is there an alternative function itself to array_map that can mutate collection content, in my case the "name"? Perhaps some function that comes with Laravel itself?
Hmm, perhaps I am doing it too complicated.
Can I use map() directly on a model like:
When I tried this code, I got:
Ignition highlights this line:
Any idea how I can mutate existing name for the option label in the checkbox using map() or other method?When I tried this code, I got:Yes. You used pluck.
$item
== the name of the car
You could debug this, if you just dd()
ed $item
Thanks, it's working now, if I just do
$item . '<b>test</b>'
Although, it's outputed as a string
Any idea how to make it render as html ?
so the <b> tag will make the "test" bold?Solution
Use
new HtmlString()
. And probably also ->allowHtml()
on the selectGREAT! Thanks! This:
return new HtmlString($item['name'] . '<b>test</b');
is working.