语法::p arameterize() 必须是数组类型
2022-08-30 19:58:55
我收到此错误
传递给 Illuminate\Database\Grammar::p arameterize() 的参数 1 必须是数组的类型,给定的字符串,
当我尝试使用选择表单添加我的视图时。但是当我删除它时,我没有得到任何错误。我只是尝试在选择列表中输入多个值。我需要用于此目的吗?array[]
foreach
视图
<div class = "form-group {{ $errors->has('approver') ? ' has-error' : '' }}">
<label for = "approver" class = "control-label">Approver:</label>
<select name = "approver[]" multiple class = "form-control select2-multi">
@foreach ($approver as $list)
<option value = "{{ $list->id }}">{{ $list->username }}</option>
@endforeach
</select>
@if ($errors->has('approver'))
<span class = "help-block">{{ $errors->first('approver') }}</span>
@endif
</div>
控制器
public function getDocuments()
{
$approver = DB::table('users')->where('id', '!=', Auth::id())->get();
return view ('document.create')->with('approver', $approver);
}
public function postDocuments(Request $request)
{
$this->validate($request,
[
'title' => 'required|regex:/(^[A-Za-z0-9 ]+$)+/|max:255',
'content' => 'required',
'category' => 'required',
'recipient' => 'required',
'approver' => 'required',
]);
$document = new Document();
$approve = new Approve();
$user = Auth::user();
//Request in the form
$document->title = $request->title;
$document->content = $request->content;
$document->category_id = $request->category;
$approve->approver_id = $request->approver;
$approve->save();
$document->save();
$document->sentToApprovers()->sync([$approve->id],false);
}
更新
我死了并转储变量并给出了一个值数组。$approver
此外,die并转储,正如您在此处看到的,我在选择列表中输入了4和5的id。$request