Search code examples
phplaravellaravel-5laravel-validation

max:size method doesn't exist


User needs to have ability to limit upload size and I set that variable and now validation is giving me problems. I have this in my validation

$var = Model::where('id','=','1')->first();
$up=$var->size;

Validation

$this->validate($request, [
        'file' => "'max:".$up."'",
        ]);

and it says

Method [validate'max] does not exist.

Solution

  • Assume $up = 10; then validation string must be 'max:10'. Removing single quotes around the max will solve the problem.

    So you have to change yout code from:

    'file' => "'max:".$up."'" to

    'file' => "max:".$up