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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With