jeudi 8 novembre 2018

Laravel: How can I write my own conditional validator?

I have a form that asks for several files, and description of these files. Something like

<input type="file" name="file1">
Describe your file:
<input type="text" name="desc1">

I want the user to describe the contents of the file, instead of only showing something like Invoices-final-FinalV30.docx he might say "Invoices for January, 2018", so when I validate the form, I know how to ask if a field follows a regex, or if the field is required and so on, using the validate() method, but I want something custom, something that makes "desc1" required ONLY if there's a "file1", if there's no "file1" I can safely ignore whatever "desc1" carries.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire