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');