Foks's avatar
Level 15

Validation of filetypes?

Hello!

I'm currently working on a file upload functionality for a site, I need to create a validation where the allowed file types can vary. Fx. Recipe 1 allows only .jpg & Recipe 2 allows only .png, .docx and so on?

0 likes
2 replies
kevinwakhisi's avatar

you could try something like this


'recipe1' => 'required|image|mimes:jpg'
'recipe2' => 'required|mimes:png,application/vnd.openxmlformatsoffice-document.wordprocessingml.documentdocx'

Foks's avatar
Level 15

@iamkevinwakhisi Okay I might not have explained what I mean in-depth. I'm going to use another example.

When I (as a teacher) creates assignments for students, I should say that this assignment only allows .pdf files. But another assignment should allow .pdf and .docx, but it is the same form? If that makes sense.

Like I have a creation assignment-creation.blade.php, I have a field called allowed_types, where the teacher can select allowed filetypes. These file types can differ from assignment to assignment.

Please or to participate in this conversation.