OunknownO
OunknownO

Reputation: 1196

laravel validation add custom var

I wan't to give user ability to limit upload file size.

    $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',
         ]);

And it throws out error

Method [validate'max] does not exist.

Upvotes: 0

Views: 60

Answers (1)

ka_lin
ka_lin

Reputation: 9432

You have extra quotes, correct:

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

Upvotes: 4

Related Questions