我在使用Laravel获取表单请求以查找多选输入时遇到问题。我的请求输入始终显示为NULL。我的语法中是否有任何遗漏或错误的内容?
我已经看到一些例子提到了Laravel中多选的点符号语法?
e.g。
$name = $request->input('products.0.name');
$names = $request->input('products.*.name');
但是我假设这是多维选择?
我将请求传递到存储库以进行数据操作
<select id="team" name="team[]" class="team" multiple>
@foreach ( $teams as $team )
<option value="{{ $team->id }}">{{ $team->name }}</option>
@endforeach
</select>
use Illuminate\Support\Facades\Input;
public function createUser( CreateUserRequest $request ){
$array = DB::transaction(function($request) use ($request)
{
$name = $request->input('name');
$email =$request->input('email');
// $team = $request->input('team[].*');
$s = $request->input('team');
$t =$request->get('team');
var_dump($s);//NULL
var_dump($t);//NULL
die();
答案 0 :(得分:1)
请检查它是否有效。
$name = $request->input('name');
$email =$request->input('email');
// array field
$team = $request->input('team');
foreach($team as $key=>$value){
$data->name = $name;
$data->email = $email;
// array value
$data->item = $value;
// save in datatabase
$data->save();
}