Reputation: 23
i have a multi select dropdown that take recoreds from database as options , so i need to get the id list of selected records
<div class="field">
<label>Mailer</label>
<div class="ui fluid multiple search selection dropdown">
<i class="dropdown icon"></i>
<div class="default text">Select Mailer</div>
<div class="menu">
@php
use App\Mailers;
$mailers=Mailers::all();
@endphp
@foreach ($mailers as $mailer)
<div class="item">{{ $mailer->fname }}</div>
@endforeach
</div>
</div>
</div>
Upvotes: 0
Views: 1145
Reputation: 6233
Use array in name attribute that will hold the selected options
<div class="menu">
@php
use App\Mailers;
$mailers = Mailers::all();
@endphp
<select multiple name="mailId[]">
@foreach ($mailers as $mailer)
<option value="{{ $mailer->id }}">{{ $mailer->fname }}</option>
@endforeach
</select>
</div>
As you are using a form you will get the form values in controller in Request object. So in controller
foreach ($request->mailId as mail_id) {
//here what you need to do with the ids.
}
It's a bad practice to use php in blade/view. Load variables from your controller instead.
Upvotes: 2