1

I have the following in my controller:

$companies = Company::pluck('title', 'id')->toArray();

Which gets send to a view with a form using Laravel Collective. Inside this view i have the following piece of code to show the array in the select box:

<div class="form-check">
      {{ Form::label('company_id', 'Bedrijf', ['class'=>'label']) }}<br>
      {{ Form::select('company_id', $companies, null, ['class' => 'form-control chosen-select', 'placeholder' => 'None', 'id' => 'company_id']) }}
</div>

This generates the given title in a dropbox, as intended. However, i want my ID's to be the same as my company_id from my controller. Now it's just a list from 0 to the array's length. To clarify: the desired result should look like:

<li class="active-result" data-option-array-index="Company id">Company title</li>
<li class="active-result" data-option-array-index="Company id">Company title</li>
<li class="active-result" data-option-array-index="Company id">Company title</li>

However, my indexes are just incremental and do not correspond with the company id's at all:

<li class="active-result" data-option-array-index="0">Company title</li>
<li class="active-result" data-option-array-index="1">Company title</li>
<li class="active-result" data-option-array-index="2">Company title</li>

How can I achieve this?

El Klo
  • 173
  • 3
  • 14
  • I'm not sure what you mean. This seems to generate the correct selectbox where the values are the company id's and the display value is the company's name. – Flame Jan 06 '20 at 12:53
  • I clarified my question. The values are just incremental and not the company id's. – El Klo Jan 06 '20 at 13:04
  • `Form::select(...)` should generate an ` – Flame Jan 06 '20 at 13:09

0 Answers0