我收到此错误“传递给Illuminate Database Grammar :: parameterize()的参数1必须是类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了我收到此错误“传递给Illuminate Database Grammar :: parameterize()的参数1必须是类型相关的知识,希望对你有一定的参考价值。
当我尝试将数据插入到我的表中时,会发生此错误
传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须是类型数组,给定字符串,在C:\ xampp \ htdocs \ Portal \ vendor \ laravel \ framew中调用...
view
<form method="post" action=" route('notice.store') ">
csrf_field()
<div class="form-group">
<label for="Select Group to Post Notice">Select Group to Post Notice </label>
<select class="bg-white text-danger form-control " name='GroupID[]' multiple>
@foreach ($users as $user)
<option value=" $user->GroupID "> $user->GroupID </option>
@endforeach
</select>
</div>
<div class="form-group">
<label for="Enter Notice">Enter Notice</label>
<input class="bg-white text-danger p-2 form-control form-control-sm" type="text" name="Notice" placeholder="Enter Notice">
</div>
<input class="btn btn-danger btn-lg px-5" type="submit" name="submit">
</form>
controller
public function store(Request $request)
$member = $request->input('GroupID');
foreach($member as $value)
$storeInfo = new notice();
$storeInfo->GroupID = $request->input('GroupID');
$storeInfo->Notice = $request->input('Notice');
$storeInfo->save();
return redirect('/notice');
答案
我想你得到这个错误的原因是因为:
$storeInfo->GroupID = $request->input('GroupID');
$request->input('GroupID')
将返回一个数组(name='GroupID[]'
),而不是个人id。
由于您已经循环遍历组ID,因此您可以使用GroupId
的值:
public function store(Request $request)
foreach ($request->input('GroupID') as $groupId)
$storeInfo = new notice();
$storeInfo->GroupID = $groupId; //<--here
$storeInfo->Notice = $request->input('Notice');
$storeInfo->save();
return redirect('notice');
另一答案
尝试更改控制器逻辑
public function store(Request $request)
//
$member=$request->input('GroupID');
foreach($member as $value)
$storeInfo = new notice();
$storeInfo->GroupID = $value;
$storeInfo->Notice = $request->input('Notice');
$storeInfo->save();
return redirect('/notice');
以上是关于我收到此错误“传递给Illuminate Database Grammar :: parameterize()的参数1必须是类型的主要内容,如果未能解决你的问题,请参考以下文章