[英]Type error: Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given
[英]Argument 1 passed to Illuminate\Database\Grammar::parameterize() must be of the type array, string given
它清楚地表明$ file_ids是數組類型但仍然得到這個錯誤,我使用不同的函數來知道變量的數據類型,如gettype()它也返回array.please幫助我擺脫這種頭痛。 提前致謝。
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
所以確保你使用相同的變量。
另外你確定$file_ids
數組中有有效值嗎?
看評論的問題是:
$downloadLink->file_ids = $file_ids;
在makeDownloadLink
方法中。
你正在做這樣的事情:
if (count($file_ids) > 1) {
$downloadLink->file_ids = implode(',', $file_ids);
}
$downloadLink->file_ids = $file_ids;
當$file_ids
是數組時,這將失敗。 你應該在這里添加else
:
if (count($file_ids) > 1) {
$downloadLink->file_ids = implode(',', $file_ids);
}
else {
$downloadLink->file_ids = $file_ids;
}
檢查這段代碼
$files = File::get($file_ids);
用find()
替換get()
find()
$files = File::find($file_ids);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.