Laravel 5.6 - Collection could not be converted to int

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....

July 31, 2018 | Category : PHP Laravel Laravel 5 Laravel 5.5 Laravel 5.6
Related Posts