I have a Laravel form whose route is '/{Parameter1}/{Parameter2}/{Parameter3}' and I have also created a default route to which the user is redirected in case they type anything in those three parameters.
What I would like to know is how to redirect the user to the default page in case he writes more than three parameters, be it 4, 5, 10, 20, etc.
These are the routes I have:
// Ruta después de iniciar sesión
Route::get('/home', 'HomeController@index')->name('home');
// Ruta del botón configuración
Route::resource('configuracion', 'ConfiguracionController');
Route::get('/configuracion/{id}/generate', 'ConfiguracionController@generate');
// Ruta para ir al Formulario
Route::get('/formulario', 'FormularioController@predeterminado');
Route::get('/formulario/{origen?}/{tipoprograma?}', 'FormularioController@procesar');
Route::get('/formulario/{origen?}/{tipoprograma?}/{codigo?}', 'FormularioController@procesar');
// Ruta de la página por defecto
Route::get('/landing', 'LandingController@predeterminado');
// Ruta que lleva a la Landing Page
Route::get('/{origen}/{tipoprograma?}', 'LandingController@procesar');
Route::get('/{origen}/{tipoprograma}/{codigo}', 'LandingController@procesar');
// Ruta que recibe la información del formulario de la landing
Route::post('landing-cep', 'LandingController@store')->name('landing-cep');
For a sample, when I enter the page with three parameters it appears like this:
But when I enter with 4 or more parameters in the URL I get an error:
I managed to solve it as follows:
I go to the file app/Exceptions/Handler.php
I import: use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
Then we go to the render method and leave it like this: