2016-11-10 170 views
0

我不想給用戶限制上傳文件大小的能力。laravel驗證添加自定義變量

$uploadSize = Settings::where('id','=','1')->first(); 
    $upSz=$uploadSize->uploadSize; 
    $upMz="'max:".$upSz."'"; 
    $this->validate($request, [ 
     'file' => $upMz, 
     'file' => 'mimes:doc,docx,xslx,ppt,pptx,zip,rar,pdf', 
     ]); 

它拋出錯誤

Method [validate'max] does not exist. 

回答

4

你有額外的引號,正確的是:

$upMz="max:".$upSz.""; 
$this->validate($request, [ 
     'file' => $upMz, 
     'file' => 'mimes:doc,docx,xslx,ppt,pptx,zip,rar,pdf', 
     ]);