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.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community