Skip to content
Advertisement

Redirect to route in laravel not working

I am working on Laravel 5.4.36 application where my route label is defined in web.php as,

Route::get('/label/', 'LabelController@index');

but when I am trying to redirect from a control function to a route label using,

return redirect()->route('label');

Error: InvalidArgumentException Route [label] not defined.

or

return Redirect::to('label');

Error: FatalErrorException Class ‘AppHttpControllersRedirect’ not found.

both are not not working, Can anyone help me how to redirect to a route in Laravel?

Advertisement

Answer

route() redirects to a named route, so you need to name your route in your routes/web.php:

Route::name('label')->get('/label/', 'LabelController@index');

https://laravel.com/docs/5.4/routing

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement