0

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?

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your response, I'll try bootstrap-multiselect

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.