Reputation: 798
I want to have a form like this:
<form>
<select name="color">
<option style="background: red">RED</option>
<option style="background: green">GREEN</option>
<option style="background: blue">BLUE</option>
</select>
</form>
How can I do this with Laravel Blade?
Upvotes: 2
Views: 5171
Reputation: 2525
First you need to install laravelcollective/html package through Composer. than you can use like this:
{{
Form::select('color', ['red' => 'RED', 'green' => 'GREEN', 'blue' => 'BLUE'], null, ['class' => 'form-control']);
}}
Upvotes: 0
Reputation: 163898
I guess you're asking about how to build select list with Laravel Collective Form::
and add custom class to each option.
In this case, I would recommend you to create custom macro.
It's easy to define your own custom Form class helpers called "macros". Here's how it works. First, simply register the macro with a given name and a Closure
Form::macro('customCssSelect', function()
{
return '<select>your HTML and PHP here</select>';
});
And then use it to build dropdown list:
Form::customCssSelect();
Upvotes: 1