Question

I am creating a package in my Laravel install and within my controller I have set up some rules. One of my rules is for a file upload to be a pdf.

I have...

$rules = array(
        'brochure'      => 'mimes|pdf'
    );

When I go to save my file, it says Method [validatePdf] does not exist. In another package I have an image rule saying...

$rules = array(
        'image' => 'required|image'
    );

This works and validates perfectly fine. How come one rule works and another doesn't? I've tried changing the mimes to jpg and it still couldn't find a validateJPG method either. Could this be because I'm working inside a package and it's trying to find it in there? If so, how would I go about changing this so it looks outside of my package for the method?

Was it helpful?

Solution

By using a pipe to separatem them, you were telling Laravel you have a custom pdf validator, this is the way you tell it to use the pdf mime validator:

$rules = array(
    'brochure'      => 'mimes:pdf'
);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top