Hi! is there a way to require a minimum amount of files/images to be uploaded in the fileupload field? There is maxFiles… but I’d need also “minFiles”.
I already thought of making multiple upload fields, but I’d like to keep it as one field and the client be able to drag reorder them. I know I can do that with a repeater of single fileuploads… but I think it’s overkill. I’d like to keep the UI simpler.
Here a solution (to put in your model):
public function beforeSave() {
$sessionKey = \Input::get('_session_key');
$files = $this->files()->withDeferred($sessionKey)->get();
if ($files->count() < 2) {
throw new \ApplicationException('Add at least 2 files.');
}
}
Replace “files()” with your relation.
Another thing; limit - How do I set dropzone to upload if only a minimum of 10 files are on the qeue? - Stack Overflow
1 Like
In latest version, you can use the between
rule definition too:
public $rules = [
'files' => 'required|between:1,2',
];