When a form is submitted and it passes its validation which is defined in the ValidateTicketData extends FormRequest
-Class you get to a site where there is displayed your form inputs.
There's also an <input type="file" />
to upload a file.
The Validation rules for this is defined in the ValidateUploadedFile extends FormRequest
-Class.
When the file passes the validation, there should be displayed something like "file has been uploaded successfully" or so.
Here's the Controller-method:
public function store(ValidateFormData $request, ValidateUploadedFile $requestFile, $param = '')
{
$validated = $request->validated();
$formData = $request->all();
if ($requestFile->hasFile('file')) {
$file = $requestFile->file('file');
if ($file->validated()) {
$filename = uniqid() . $file->getClientOriginalName() . '.' . $file->getClientOriginalExtension();
$file->storeAs('store', $filename);
$file->move(public_path('store') . $filename);
}
}
return view('/validation', compact('formData'));
}
I was thinking about something like this.
If I leave out the part of the $requestFile... (so that the Controller would look like this:)
public function store(ValidateFormData $request, $param = '')
{
$validated = $request->validated();
$formData = $request->all();
return view('/validation', compact('formData'));
}
... it works just fine.
The 'validation'-Site is displayed with the validated form inputs.
I somehow think this has something to do with the second Request class $requestFile
, but I really don't know how to do it.
Since the file can be validated only after the form data is already validated I need two seperate Request classes..
I hope someone can help me with this.