1
votes

I'm trying to redirect a route from a controller function after a form submit process in Laravel 5.4 as it is said in link below

https://laravel.com/docs/5.4/redirects#redirecting-named-routes

Route;

Route::group(['middleware' => ['api'], 'prefix' => 'api'], function () {
    Route::post('doSomething', 'Page@doSomething');
});


Route::post('/profile', function () {
    //..
});

Controller;

public function doSomething(Request $request){
   return redirect()->route('profile', ['id'=>1]);
}

When I try to redirect I get this error.

InvalidArgumentException in UrlGenerator.php line 304: Route [profile] not defined.

I have searched several times about redirection but I got similar results.

Any suggestions ? Thank you.

1

1 Answers

3
votes

route() works with named routes, so name your route

Route::post('/profile', function () {
//..
})->name('profile');