laravel验证添加自定义var

时间:2016-11-10 15:03:25

标签: php laravel laravel-5 laravel-5.2

我不能让用户限制上传文件的大小。

    $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.

1 个答案:

答案 0 :(得分:4)

你有额外的引用,正确:

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