Support the ongoing development of Laravel.io →
Requests Input Validation

So I have this form that on the main website, that uses file[] for the form field. That works fine.

However, a 3rd party app uses the standard file field, making it a single-file upload form.

How can I modify the input so that it makes all files, regardless if single or multiple, into a multiple file array?

This is what I tried so far:

protected function getValidatorInstance()
		{
			if(isset($this->all()['file']))
			{
				$formatted = [];
				
				if($this->all()['file'] instanceof UploadedFile)
				{
					$formatted['file'][] = $this->all()['file'];
				}
				else
				{
					foreach($this->all()['file'] as $file)
					{
						$formatted['file'][] = $file;
					}
				}
				
				$this->replace($formatted);
				
				return parent::getValidatorInstance();
			}
			
			echo json_encode([
				'error' => true,
				'message' => 'Could not find the "file" field.',
			]);
			
			die;
		}

For some odd reason, the replace() method doesn't do its job properly. This is on Laravel 5.2.

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

TechKat techkat Joined 19 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.