I have a two step validation form, that means the first user input gets validated (within a ValidateTicketData-Controller) and if everything's correct you get to the next form page, which I get to by
Route::post('/{locale?}/ticket/{cat?}', 'TicketController@store')->name('validation');
Problem: On the second page the user is required to upload a file, if he doesn't the validation fails.
If this is the case the validator class immediately redirects which doesn't work since it's a post-route.
So I created a get route like this:
Route::get('/{locale?}/ticket/{cat?}', 'TicketController@store')->name('validation');
and put this in the store
-method:
$ticketData = $request->validated();
if ($request->isMethod('get')) {
$error = 'No pdf-file has been attached.';
return view ('/validation', compact('ticketData', 'cat', 'error'));
}
I put this into the store
-method because this is where the user gets redirected if he won't attach a file on the second page.
But if I now try to send the form without attaching a file I get the message that I've redirected too many times
.
I can't find a solution how to redirect to the 'validation`-page with the validated input from the first page (because it gets displayed again) since the Validation class does it automatically.
EDIT
I changed the get-route to this:
Route::get('/{locale?}/ticket/{cat?}', function() {
$error = 'no pdf tho.';
return view('/validation', compact('error'));
});
and displayed the $error (if it's not empty) in the view. This worked, but I still don't know how to get the input data from the first page.
I also have this middleware for the $locale
public function handle($request, Closure $next)
{
$locale = $request->segment(1);
app()->setLocale($locale);
return $next($request);
}
which seems to won't let me redirect sometimes, I don't really understand it