[英]How to return the list of selected values from multiselect in laravel?
i have a multi select dropdown that take recoreds from database as options , so i need to get the id list of selected records我有一个多选下拉菜单,它从数据库中获取记录作为选项,所以我需要获取所选记录的 id 列表
<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>
Use array in name attribute that will hold the selected options在 name 属性中使用数组来保存所选选项
<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.
在刀片/视图中使用 php 是一种不好的做法。 Load variables from your controller instead.
而是从控制器加载变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.