Reputation: 611
I'm trying to build a form to assign a reward to an item (I call it a "ticket"). I want a dropdown list with all of the tickets so that the person can then choose.
This is my controller
$tickets = Ticket::all();
return view('rewards.create',compact('tickets'));
And in my blade.php view
<div class="form-group">
{!! Form::label('ticket','reward for: ') !!}
{!! Form::select('id', $tickets, Input::old('id')) !!}
</div>
This works, but it shows all the fields of the object. I want it show two fields. To store the 'id' in the vallue and 'description' in the written field of the select box, but doing something like
{!! Form::select('id', $tickets->description, Input::old('id')) !!}
brings up an error. Can anyone please help?
Upvotes: 1
Views: 1393
Reputation: 152860
The options have to be passed as array: ['value' => 'text']
. You can use lists()
to build that array for you:
$tickets = Ticket::lists('description', 'id');
return view('rewards.create',compact('tickets'));
Upvotes: 2
Reputation: 379
In your blade.php
<div class="form-group">
{!! Form::label('ticket','reward for: ') !!}
{!! Form::select('id', $tickets->id, Input::old('id')) !!}
{!! Form::select('description', $tickets->description, Input::old('description')) !!}
</div>
Upvotes: 0