Laravel Drop Down Multiple Values from Db in Drop Down

Laravel drop down multiple values from DB in drop down

You could get the fields you need in the controller:

$projects = Project::where('project_id', '=', Session::get('project_id'))->get('id', 'project_name', 'created_by');

Then pass it to the view:

return View::make('my.view', array('projects' => $projects));

There you create the option tags manually:

<select class="form-control" name="project">
@foreach($projects as $project)
<option value="{{ $project->id }}">{{ $project->project_name }} {{ $project->created_by }}</option>
@endforeach
</select>

The second dropdown value for multiple dropdown value NOT SAVE in database using laravel

The issue is with option value wrongly passed in jquery.It should be data[i].code instead of data[i].id

op+='<option value="'+data[i].code+'">'+data[i].code+" "+data[i].description+'</option>'

Also you might need to update query as well to show description

$data=ShiftPattern::select('code','id','description')->where('id',$request->id)->take(100)->get();

Multiselect Box with Laravel and values from database

use in_array() to check

 $prodmulti = explode(',', $prodmulti);

return view('admin.users.edit', compact(['user', 'roles', 'countries', 'states', 'productcategories', 'prodmulti']));

then in blade

<div class="col-lg-8 col-xl-5">
<div class="form-group">
<select class="js-select2 form-control" id="prodmulti" name="prodmulti[]" style="width: 100%;" data-placeholder="Choose many.." multiple>
<option></option>
@foreach($productcategories as $productcategory)
<option value="{{ $productcategory->id }}"
{{ in_array($productcategory->id,$prodmulti) ? "selected" : "" }}>
{{ $productcategory->name }}
</option>
@endforeach
</select>
</div>
</div>

How to load items in AdminLte multi select dropdown for update - Laravel 8

Your should check $player->id in $players's ids instead in checking players array where that array dosen't contain the ids. So I will pluck the ids of $players from the collection and then convert it into a array $players->pluck('id')->toArray().

{{ in_array($player->id, $players->pluck('id')->toArray()) ? "selected": ""}}

or you can get model keys (ids) from the controller via

$playerIds = User::whereRoleIs(['player'])->modelKeys();

#modelKeys()

Then just check that array in your select option loop.This will save users RAM

 {{ in_array($player->id, $playerIds) ? "selected": ""}}

I am using select 2 multiselect drop down in laravel .On click select all all values get selected in laravel?

This will help you!

$('.service_continent').select2();
$('.service_continent').on('change', function(event) {
event.preventDefault();
if ($(this).val() == 'all') {
// select all options except first one
$('.service_continent > option:not(:first)').prop('selected', true);

// unselect "Select All" option
$('.service_continent > option:first').prop('selected', false);
$('.service_continent').trigger('change');
}
});


Related Topics



Leave a reply



Submit