So it took my time and bored me so much and I wanted to ask you!
<select>
@foreach($items as $item)
<option value="{{$item->name}}">{{$item->name}}</option>
@endforeach
</select>
I am ok with this example i mean i can get items in dropdown list. But! When I try to do it in laravel forms, I cant make the same! I cant place the foreach loop inside of forms of laravel
<div class="form-group">
@foreach($items as $item)
{!! Form::select('name', [$item->name => $item->name]) !!}
@endforeach
</div>
So in the end i get this.. difference
https://pasteboard.co/GRYceaG.png
I know that i need to put this foreach loop after select in {!! Form::select('name',
but i cant do it! Help me about this damn stupid problem please.
Form::select
creates a <select>
. So you create a <select>
on every iteration. Instead, you need to:
{!! Form::select('name', $options) !!}
where $options
is array with your values. You can create this array in a controller.
For example, you can pluck
required field from collection and pass the result array to select()
:
$options = $user->items()->pluck('name');
{!! Form::select('name', $options) !!}