Php 为什么我会得到;传递给Lightning\Database\Grammar::parameterize()的参数1必须是数组类型,字符串为“给定”;
当我使用MySQL而不是SQLite时,我在生产中遇到了这个错误。我犯了一个以前从未犯过的错误 当我尝试通过我的表单发送数据时,会出现以下异常:Php 为什么我会得到;传递给Lightning\Database\Grammar::parameterize()的参数1必须是数组类型,字符串为“给定”;,php,mysql,laravel,Php,Mysql,Laravel,当我使用MySQL而不是SQLite时,我在生产中遇到了这个错误。我犯了一个以前从未犯过的错误 当我尝试通过我的表单发送数据时,会出现以下异常: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given 下面是我用来将数据放入数据库的代码: public function store(Request $request) {
Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given
下面是我用来将数据放入数据库的代码:
public function store(Request $request)
{
if(isset($request['recommended'])) {
$request['recommended'] = true;
} else {
$request['recommended'] = false;
}
$validated = $request->validate([
'title' => 'required|string',
'recommended' => 'required|boolean',
'us' => 'string',
'ca' => 'string'
]);
$item = new Item();
$item->fill($validated);
$item->save();
$validated['item_id'] = $item->id;
ItemLink::create($validated);
return redirect()->route('items.index');
}
错误似乎发生在$item->save()行
我试图转储$validated变量,其内容如下:
array:4 [
"title" => "Echo Show 8"
"recommended" => false
"us" => "asdaksjdkasj"
"ca" => "asdasdsad"
]
我知道我应该传递一个数组,但我不明白为什么以及如何传递。问题出现在项目模型中。我有一个自定义的受保护属性,名为$attributes,它是一个数组。在获取对象时,我使用它附加了一些属性
然而,出于一个我仍然不理解的原因,Laravel尝试将其用作数据库值。我只需将该属性设置为“public”,一切都正常工作。问题在于项目模型。我有一个自定义的受保护属性,名为$attributes,它是一个数组。在获取对象时,我使用它附加了一些属性 然而,出于一个我仍然不理解的原因,Laravel尝试将其用作数据库值。我只需将该物业设置为“公共”,一切正常