Ad

Laravel 5.1 Add A Blank Value To Form::select() With $model->lists()

- 1 answer

I have a form that has a select input that called customer_id. This field is not required, and I fetch the options via the Customer Model. My code looks like this:

{!! Form::select('customer', $customers->lists('email', 'id'), null, ['class' => 'form-control']) !!}

so far so good, right? but the thing is that when I don't want to choose a customer, I can't choose a blank option. Is there a way to add a blank option so I wouldn't need to pick a customer all the time?

Ad

Answer

[''=>'---']+$customers->lists('email', 'id')->toArray()

or

array_merge([''=>'---'], $customers->lists('email', 'id')->toArray())
Ad
source: stackoverflow.com
Ad