gpt4 book ai didi

php - Grammar::parameterize() 必须是数组类型

转载 作者:可可西里 更新时间:2023-10-31 22:13:28 26 4
gpt4 key购买 nike

我遇到了这个错误

Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given,

当我尝试使用选择表单在我的 View 中添加 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>

Controller

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 变量并给出了一个值数组。

SC

同时退出并转储 $request 正如您在这里看到的,我在我的选择列表中输入了 45 的 ID。

SC

最佳答案

好的,您的问题是您正试图将数组保存为一个奇异值,而您需要在其中迭代审批人。

将您的 Controller 逻辑更改为:

foreach ($request->approver as $approver) {
$approve = new Approve();
$approve->approver_id = $approver;
$approve->save();

$document->sentToApprovers()->sync([$approve->id],false);
}

关于php - Grammar::parameterize() 必须是数组类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38957486/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com