第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Laravel 5.7 在控制器中循環(huán)時(shí)為 foreach() 提供的參數(shù)無(wú)效

Laravel 5.7 在控制器中循環(huán)時(shí)為 foreach() 提供的參數(shù)無(wú)效

PHP
Qyouu 2021-06-16 13:42:42
當(dāng)我嘗試在控制器內(nèi)部執(zhí)行循環(huán)時(shí),出現(xiàn)錯(cuò)誤Invalid argument supplied for foreach(),但我真的不知道為什么。我有一個(gè)form應(yīng)該可以上傳多個(gè)文件的地方這是我到目前為止所得到的:use App\SingleApplication;use App\SingleApplicationFile;$application = SingleApplication::create([   'email' => request()->email,   'name' => request()->name,    ...// more fields]);$allowedfileExtension = ['pdf', 'jpg', 'png', 'docx'];$files = request()->has('attachment');if ($files) {     foreach ($files as $file) {       $filename = $file->getClientOriginalName();       $extension = $file->getClientOriginalExtension();       $filesize = $file->getSize();       $check = in_array($extension, $allowedfileExtension);       if ($check) {         foreach ($file as $att) {         $filename = Storage::disk('local')->put('attachments', request()->file($att));          SingleApplicationFile::create([             'files_id' => $application->id,             'single_application_id' => $application->id,             'attachment' => $filename,             'attachment_name' => $extension,             'attachment_size' => $filesize,          ]);        }     }  }}那么,我在這里做錯(cuò)了什么?
查看完整描述

1 回答

?
瀟瀟雨雨

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊

這是一個(gè)布爾值


$files = request()->hasFile('attachment'); // return  if has file not array of files

你應(yīng)該得到文件


$files = request()->file('attachment'); // returns array of files

或者您可以將條件更改為


$hasfiles = request()->hasFile('attachment');


if ($hasfiles) {


    $files = request()->file('attachment');

    // your rest code

注意:文件檢查應(yīng)該使用 hasFile 來(lái)完成,因?yàn)槲募推渌侄问遣煌摹?/p>


查看完整回答
反對(duì) 回復(fù) 2021-06-25
  • 1 回答
  • 0 關(guān)注
  • 208 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)