Volatil3
Volatil3

Reputation: 15016

Laravel: How to insert an item in Select which is pre populated with records?

I am using Laravel 5.1. In form I am generating drop down as:

{!! Form::select('ptype', $p_types,null,['class' => 'form-control text-capitalize']) !!}

While in controller $p_types is set as:

$p_types = PType::lists('name', 'id');

I want to show an option as Select here on top of drop down. How do I do tat?

Upvotes: 0

Views: 79

Answers (2)

Kiran Subedi
Kiran Subedi

Reputation: 2284

You can also do like this in blade template to add the Select here option on top of drop down

{!! Form::select('ptype',([''=>'Select here']+$p_types->toArray()) ,null,['class' => 'form-control text-capitalize']) !!}

Upvotes: 0

djowinz
djowinz

Reputation: 356

There is no simple solution to doing what you're asking, as mentioned here. Form:recipes add placeholder attribute What you can do is in the lists method insert a record into the collection before it's passed to the blade template. Checkout this link Collection Methods. That is by far the easiest solution.

$p_types->push("Select Here");

Upvotes: 2

Related Questions