Reputation: 89
Hey guys I have a project-create form where I want an the ability to select multiple users for a project
So far I've achieved this much:
Hey guys, so here's my code and what I want is different
<div class="form-group">
<strong>User :</strong>
<br/>
@foreach($users as $value)
<label>{{ Form::checkbox('user[]', $value->id, false,
array('class'=>'name')) }}
{{ $value->name }}
</label>
<br/>
@endforeach
</div>
My ProjectController.php
public function create()
{
//
$users = User::all();
return view('admins.projects.create', compact('users'));
}
Now this works just fine, the thing is I get multiple checkboxes and it's messy.
I'm using Admin LTE and I want to use the following html snippet instead of Checkbox code:
<div class="form-group">
<label>Multiple</label>
<select class="form-control select2" multiple="multiple" data-
placeholder="Select a State" style="width: 100%;">
<option>Alabama</option>
<option>Alaska</option>
<option>California</option>
<option>Delaware</option>
<option>Tennessee</option>
<option>Texas</option>
<option>Washington</option>
</select>
</div>
This design is a better and less messy alternate to checkboxes. I am not able to make it work by changing it to
LaravelCollective docs:
Form::select('size', array('L' => 'Large', 'S' => 'Small'), null,
array('multiple' => true));
Can someone help me?
Upvotes: 0
Views: 8787
Reputation: 390
Something I always use is:
<div class="form-group col-md-12">
{!! Form::label('users[]', 'Role') !!}
{!! Form::select('users[]',$users, null, ['class' => 'form-control', 'multiple']) !!}
</div>
Where you have to hold the CTRL button to select multiple users. The [] is important because php otherwise will not reconize the input as an array.
If you want something more fancy you can try something like this: https://github.com/davidstutz/bootstrap-multiselect
Upvotes: 2