Actually, i was working on my laravel 5.6 new project and i require to create dropdown box from database data. I am using laravel "laravelcollective" for select box. I simply created select box with Form::select() element. Then simply i was getting data array using pluck method and i want one black option for just write "Select Form Type", then i simply add following way but i got following error:
"Collection could not be converted to int"
And my form select was this way:
{!! Form::select('search', ['' => 'Select Form Type'] + $formType, null, ['class' => 'form-control']) !!}
i tried to many way but can't find solution to complete select box dynamic. But finally i search on google and found solution to fix this issue two way. I added both solution bellow so you can understand and solve your issue too.
Solution 1:
{!! Form::select('search', ['' => 'Select Form Type'] + $formType->toArray(), null, ['class' => 'form-control']) !!}
Solution 2:
$formType = FormType::pluck('name', 'name')->prepend('', 'Select A Form');
{!! Form::select('search', $formType, null, ['class' => 'form-control']) !!}
I hope it can help you....
Do you like below Tutorials ?
- PHP Convert Date String to Datetime Object
- Laravel Validation Different Value Example
- Jquery Redirect to URL After Specific Time Example
- User Roles and Permissions in Laravel Example
- How to Get Value of Selected Option in Vue JS?
- Laravel Change Password OLD Password Validation Example
- Vue JS Get String Length Example
- How to Active and Inactive Status in Laravel?