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 ?
- Laravel 5.6 - Collection could not be converted to int
- Laravel - How to generate secure https URL from route?
- Laravel - Vue JS File Upload Example
- How to get last 7 days data in Laravel?
- Laravel Validation required if other field empty example
- Laravel Eloquent - When Case Statement in Select Query Example
- Laravel 7.x and 6.x Passing Variable to Javascript Example
- How to pass PHP variables in JavaScript or jQuery?