Reputation:
I want to populate a select box with users
from my database i need to get the id and name of the user.
I want to create a select box like the one below:
<select>
<option value="$user->id">$user->name</option>
<option value="$user->id">$user->name</option>
</select>
How can i do this?
Upvotes: 2
Views: 1388
Reputation: 452
Controller:
View::share('users', User::all());
View:
<select name="user_id">
@foreach($users as $user)
<option value="{{$user->id}}">{{$user->name}}</option>
@endforeach
</select>
Upvotes: 2
Reputation: 6355
try this:
controller
$users = User::all()->orderBy('name', 'asc')->lists('name','id');
view
{{ Form::select('user', $users , Input::old('users')) }}
Upvotes: 0