Reputation: 551
I created routes with type (POST), and when visit it directly, it get this error:
The GET method is not supported for this route. Supported methods: POST.
how to handle getting this error if anyone visit it from URL without press a form submit or something like that.
the routes:
Route::group(['middleware'=>'guest:web'], function(){
Route::post('/post-login', [LoginController::class,'postLogin'])->name('site.postLogin');
Route::post('/register-create', [registerController::class,'create'])->name('site.register.create');
});
if anyone visited these routes (type POST) directly, it will redirect him to the above error
how to handle the POST routes in laravel in this case?
Upvotes: 3
Views: 6876
Reputation:
If you want to have routes available via GET and POST you can use match()
:
Route::group(['middleware'=>'guest:web'], function(){
Route::match(['get', 'post'], '/post-login', [LoginController::class,'postLogin'])->name('site.postLogin');
Route::match(['get', 'post'], '/register-create', [registerController::class,'create'])->name('site.register.create');
});
More on Available Router Methods
Upvotes: 2