1

In my controller I am passing a multiple array to the view. The arrays that I am passing look like this:

$charts['names'] = ['Artikler lest', 'Antall kommentarer', 'Antall "bli med"', 'Tid på døgnet'];
$charts['values'] = ['Article', 'Comment', 'Thumb', 'View'];

return view('admin.charts.show',
      compact(
        'charts',
      )
    );
  }

And in my view I have a select box that looks like this:

 <div class="large-4 columns end">
     {!! Form::select('velg', $charts['names'], null, ['id' => 'timelines']) !!}
 </div>

With this I am passing just text to the select box, I would also like to pass a values so that they are connnected like this:

<option value="Article">Artikler lest</option>
<option value="Comment">Antall kommentarer</option>
<option value="Thumb">Antall "bli med"</option>
<option value="View">Tid på døgnet</option>

How would I do such thing with Laravel collective?

Ludwig
  • 1,401
  • 13
  • 62
  • 125

1 Answers1

2

Just pass through an array with the keys as the option value:

$charts = [
    'Article' => 'Artikler lest', 
    'Comment' => 'Antall kommentarer', 
    'Thumb' => 'Antall "bli med"', 
    'View' => 'Tid på døgnet'
]; 

The form builder will use the key for the value of the option. https://laravelcollective.com/docs/5.2/html#drop-down-lists

Styphon
  • 10,304
  • 9
  • 52
  • 86