Trying to submit the form using POST method and also getting the parameters via url. While accessing website.com/profile/ it doesn’t work. It returns this error message
The GET method is not supported for route profile-list. Supported
methods: POST.
I’m not sure what I’m doing wrong
Web.php
Route::get('/profile/{username}/{mobilenumber?}', [ProfileController::class, 'profileList'])->name('profile-list');
Route::post('/profile/', [ProfileController::class, 'submitForm'])->name('submit-form');
Blade form file
<form action="{{ route('submit-form') }}" method="post">
@csrf
....
</form>
ProfileController
public function submitForm(Request $request)
{
$request->validate(
...
);
$username = strtolower($request->input('username'));
$mobilenumber = strtolower($request->input('mobilenumber'));
if ($mobilenumber) {
return redirect()->route('profile-list', ['username' => $username, 'mobilenumber' => $mobilenumber]);
} else {
return redirect()->route('profile-list', ['username' => $username]);
}
}
2
Answers
Try to change your route definition like this
and also add => @method(‘POST’)
First of all, you need to add the params on the route you will use
Your form
And finally, your handler method [PLEASE SEE THE ANOTHER IMPLEMENTATION]
I tested after write this, and route helper works fine with null values, so a better approach is as following: