Skip to content

Comments

support rules as array for multiple file uploads#115

Open
simonbuehler wants to merge 3 commits intotanthammar:masterfrom
simonbuehler:file_rules
Open

support rules as array for multiple file uploads#115
simonbuehler wants to merge 3 commits intotanthammar:masterfrom
simonbuehler:file_rules

Conversation

@simonbuehler
Copy link
Contributor

allows rules for multiple files like
->rules(['files' => 'between:1,3', 'files.*' => 'required|max:1024']) so not only the individual file properties are validated but also e.g. the min/max number of uploaded files

allows rules for multiple files like
->rules(['files' => 'between:1,3', 'files.*' => 'required|max:1024'])
@simonbuehler
Copy link
Contributor Author

found a error when submitting , please don't merge

@simonbuehler
Copy link
Contributor Author

simonbuehler commented Mar 17, 2022

works so far, rules can either be

only per File Validation

FileUpload::make('Uploads', 'files')
->multiple()
->rules('required|mimes:pdf,png,jpg,jpeg,gif|max:1024')

or also for the Files Collection as well like setting it to be required or min/max number of files

FileUpload::make('Uploads', 'files')
->multiple()
->rules(['files' => 'between:1,3', 'files.*' => ['required','mimes:pdf,png,jpg,jpeg,gif','max:1024']])

Only i can't show the errors for the 'files', they are detected (e.g. no files uploaded) on submit and returned in the "errors" array but not picked up by the form, any hint on this? edit: fixed in layout

@tanthammar
Copy link
Owner

What is your reason for this change?
image

I guess if you have multiple rules it means that the field is set to be multiple?

@simonbuehler
Copy link
Contributor Author

simonbuehler commented Mar 28, 2022

this would allow to use multiple and only check the individual files ( field.name.*) or check the array (field.name) for backwards compatibility (or both)

the old behaviour was to either show only the individual files error (for multiple set) or the single file error (multiple not set)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants