Reputation: 183
i've registered a post route and set the "auth" middleware on it,everything is working properly but at the last step when i want to redirect to my registered route after authentication,an error occurred, it seems redirect() helper function uses GET method by default,but my route supports POST method.is there any way to use redirect() with POST method?!!
Route::post('match', 'HomeController@match')->name('match')->middleware('auth');
and inside my LoginController:
if ($is_match==='comes_from_match') {
return redirect()->route('match');
}else{
return redirect()->route('dashboard');
}
this leads to the following error: "The GET method is not supported for this route. Supported methods: POST."
Upvotes: 0
Views: 323
Reputation: 5662
As per latest Laravel
documentation:
Sometimes you may need to register a route that responds to multiple HTTP verbs. You may do so using the
match
method. Or, you may even register a route that responds to all HTTP verbs using theany
method:
You can use match
or any
method:
Route::match(['get', 'post'], '/', function () {
//
});
Route::any('/', function () {
//
});
Reference:
Laravel -> Routing -> Basic Routing
Upvotes: 0
Reputation: 702
Try the following:
You can use any
instead of post
it works for both get
and post
.
Route::any('match', 'HomeController@match')->name('match')->middleware('auth');
Upvotes: 1