传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须为数组类型,给定字符串 [英] Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given
问题描述
清楚地表明$ file_ids是数组类型,但是仍然出现此错误,我使用了不同的函数来知道变量的数据类型,例如gettype(),它也返回了array.请帮助我摆脱这种麻烦. 预先感谢.
It clear shown that $file_ids is array type but still getting this error, and I used different function to know the data type of variable like gettype() it also return array.please help me to get rid from this headache. Thanks in advance.
public function getFilesForLink(Request $request)
{
$file_ids = array();
$ids = $request->input('selected_file');
if (count($ids) > 0) {
foreach ($ids as $id => $value) {
$file_ids[] = base64_decode($value);
}
}
$link_id = $this->makeDownloadLink($file_ids, $_POST['password']);
if ($_POST['via'] == 'Email') {
$files = File::find($file_ids);
foreach ($files as $name) {
$files_name[] = $name->name;
}
$this->sendEmail($files_name, $link_id, $_POST['recipient'],
$_POST['subject'], $_POST['body']);
}
推荐答案
在一个地方使用$file_ids
,在其他地方使用$files_ids
,请确保使用相同的变量.
In one place you are using $file_ids
and in others $files_ids
so make sure you are using same variable.
此外,您确定在$file_ids
数组中有有效值吗?
In addition are you sure you have valid values in $file_ids
array?
看评论的问题是:
$downloadLink->file_ids = $file_ids;
inside makeDownloadLink
方法中.
inside makeDownloadLink
method.
您正在执行以下操作:
if (count($file_ids) > 1) {
$downloadLink->file_ids = implode(',', $file_ids);
}
$downloadLink->file_ids = $file_ids;
,当$file_ids
为数组时,这将失败.您应该像这样在此处添加else
:
and this will fail when $file_ids
is array. You should probably add else
here like so:
if (count($file_ids) > 1) {
$downloadLink->file_ids = implode(',', $file_ids);
}
else {
$downloadLink->file_ids = $file_ids;
}
这篇关于传递给Illuminate \ Database \ Grammar :: parameterize()的参数1必须为数组类型,给定字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!