I’m having problems trying to add custom attributes to select options using spatie/laravel-html. I’m coming over from Laravel Collective which allowed you to just submit a extra attributes collection, eg:
Controller:
$contact_detail_types = ContactDetailType::pluck('contact_detail_type','id')->all();
$option_attributes = collect(ContactDetailType::all())
->mapWithKeys(function ($item) {
return [$item->id => ['data-input-mask' => $item->input_mask]];
})->all();
Blade (Laravel Collective):
{!! Form::select('contact_detail_type_id', $contact_detail_types, null, $option_attributes) !!}
Now with spatie/laravel-html, there is no such extra variable. How do I achieve this? I tried applying a custom function to each option that would spit out the desired html, but getting an “Cannot access offset of type string on string” error before even implementing any kind of extra attributes:
{{
html()->select('contact_detail_type_id')
->children($contact_detail_types, function ($contact_detail_type){
return html()->option($contact_detail_type['contact_detail_type'], $contact_detail_type['id']);
})
->class('form-control kt-select2' . ($errors->has('contact_detail_type_id') ? ' is-invalid' : ''))
}}