Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support rules as array for multiple file uploads #115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

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.

None yet

2 participants