We help IT Professionals succeed at work.

Laravel Form Multiselect Not Showing More Than 1 Column

Ricky Nguyen
Ricky Nguyen asked
on
Hi Experts,

I'm having trouble creating a mulitselect  Laravel form to show multiple columns. This is my current setup:

Controller:
public function edit($id)
    {
        //

        $user = User::findOrFail($id);
        $assets = Asset::all()->pluck('id', 'asset_name')->toArray();

        return view($_ENV['VIEW_FOLDER_VERSION'] . '/views/users/edit', compact('user', 'assets'));
    }

Open in new window



Blade:
<div class="form-group">
        {{Form::label('assets', 'Assets')}}
        {{Form::select('assets[]', $assets ,null,array('multiple'=>'multiple','name'=>'assets[]','class'=>'form-control'))}}
      </div>

Open in new window


MySQL Table
mysql.PNG

This is what I see:
multiselect.PNG

Can you please help point me in the right direction?

Thanks,
Ricky
Comment
Watch Question

SILVER EXPERT
Most Valuable Expert 2018
Distinguished Expert 2019
Commented:
Hey Ricky,

An HTML <select> element doesn't allow for mulitple columns. The multiple that you've specified in the constructor sets the selection mode - meaning you can select multiple entries from the <select>

If you want a multi-column select, you're going to have to use something different - maybe a Javascript plugin.

Author

Commented:
Oh ok, I guess I'll have to look for another way. Thanks Chris