laravel 传递给 Illuminate\Database\Grammar::parameterize() 的参数 1 必须是数组类型,给定的字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46674623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given
提问by AGk
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.
它清楚地表明 $file_ids 是数组类型但仍然出现此错误,并且我使用了不同的函数来了解变量的数据类型,例如 gettype() 它也返回数组。请帮助我摆脱这个头痛。提前致谢。
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']);
}
采纳答案by Marcin Nabia?ek
In one place you are using $file_ids
and in others $files_ids
so make sure you are using same variable.
在您使用的地方$file_ids
和其他地方,请$files_ids
确保使用相同的变量。
In addition are you sure you have valid values in $file_ids
array?
此外,您确定$file_ids
数组中有有效值吗?
Looking at the comment the problem is:
看评论,问题是:
$downloadLink->file_ids = $file_ids;
inside makeDownloadLink
method.
里面的makeDownloadLink
方法。
You are doing something like this:
你正在做这样的事情:
if (count($file_ids) > 1) {
$downloadLink->file_ids = implode(',', $file_ids);
}
$downloadLink->file_ids = $file_ids;
and this will fail when $file_ids
is array. You should probably add else
here like so:
这将在$file_ids
数组时失败。你应该else
像这样在这里添加:
if (count($file_ids) > 1) {
$downloadLink->file_ids = implode(',', $file_ids);
}
else {
$downloadLink->file_ids = $file_ids;
}
回答by simphiwe sifiso hlabisa
check this pieces of code
检查这段代码
$files = File::get($file_ids);
replace get()
with find()
替换get()
为find()
$files = File::find($file_ids);