传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须为数组类型-Laravel [英] Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array - Laravel
本文介绍了传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须为数组类型-Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在将数据保存到数据库中,但出现此错误
I am save data into my database but i get this error
类型错误:传递给> Illuminate \ Database \ Grammar :: parameterize()的参数1必须为数组类型,给出字符串
Type error: Argument 1 passed to >Illuminate\Database\Grammar::parameterize() must be of the type array, string given
研究了其他相关问题,我试图解决此问题,但没有一个问题对我有帮助.下面是我的代码
Researching other related questions, i have tried to solve this issue but none of them has helped me yet. Below is my code
$student = Student::findOrFail($id)
if($request->file('imported-file'))
{
$path = $request->file('imported-file')->getRealPath();
$data = Excel::load($path, function($reader)
{
})->get();
if(!empty($data) && $data->count())
{
foreach ($data->toArray() as $row)
{
if(!empty($row))
{
$dataArray[] =
[
'name' => $row['name'],
'grade' => $row['grade'],
'age' => $row['age'],
'parent' => $row['parent'],
];
}
}
if(!empty($dataArray))
{
$student->teachers()->attach(\App\Teacher::create($dataArray)->id);
}
}
推荐答案
尝试替换
$student->teachers()->attach(\App\Teacher::create($dataArray)->id);
使用
$student->teachers()->createMany($dataArray);
这篇关于传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须为数组类型-Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文