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
How to Show Blob Image in HTML
Php Substring Remove Everything in a String After Certain Character
How to Get Newest Data With 'Created_At' Column
How to Create Multi Level Category Hierarchy ( Category Tree ) - Codeigniter
How to Send Data Using Redirect With Laravel
How to Get Username from Facebook Id
How to Add a Space Between Every Sequence of Four Characters (Like a Credit Card Number)
How to Delete Multiple Redis Keys With the Same Pattern in PHP Using Phpredis
How to Get Foreach Loop Variable Outside of Loop
Display Only the Current User'S Details Using PHP and MySQL
Comparing Date from Variable to MySQL Date
Mysql Return Result If 0 Rows Returned
How to Echo Selected Value of Dropdown in PHP
Laravel How to Return Single Column Value Using Query Builder