What I am trying to achieve is to redirect back to the page with validation message if the input is incorrect. Currently I am facing an error and that says.
Method Not Allowed
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for route /profile/details_options Supported methods: POST.
first in my web.php
// this is the current page basically in this page I am viewing a form wherein it will check if the employee username is valid or not...
Route::view('/check_uname', 'template.viewhere')->name('route.name');
// endpoint of the form placed in the /check_uname uri
Route::post('/profile/details_options', [FirstController::class, 'firstEndpointFunction'])->name('uname.details_options');
// endpoint of the form return view of the route('uname.details_opitons) which is the page2.displayPage
Route::post('/profile/verify_changes', [SecondController::class, 'secondEndpointFunction'])->name('verify.detail_changes');
in the check_uname
page I do have a form, and in this form I do have the endpoint of it.
so the form looks like
<form action="{{ route('uname.details_options')}}">
<-- inputs should be here -->
</form>
and now in my FirstController.php
controller.
FirstController.php
public function firstEndpointFunction(Request $request)
{
// this is where the logic goes and if the condition is true then i will fetch the data and
// pass it on the page2.DisplayPage
if(true){
return view('page2.displayPage', [
'data' => $data,
'data2' => $data2,
'data3' => $data3
]);
}
else {
}
}
and now the since the condition is true then it returned the view of page2.displayPage
with the data that I have passed but the url still remains the same which is the POST route URL: /profile/details_options
so in this page2.displayPage
now I also have a form again
<form action="{{ route('verify.detail_changes')}}">
<-- inputs should be here -->
</form>
Now in the SecondController.php
Controller is where I am having troubled at
and the the controller for this one for its endpoint is:
SecondController.php
public function secondEndpointFunction(Request $request)
{
if(true){
return response()->json(['message' => 'The input is correct.']);
}
else{
// throws the error I have mentioned aove. When the users input does not match in the DB
// my main goal is to I want to display an error message to the user that the input
// does not match in the database.
return redirect()->back()->withInput()->withErrors(['error' => 'Nothing has found.']);
}
In the last Controller the OtherController.php
is where I am having troubled at whenever the user inputs a wrong input that does not match in the database, it throws me an error, the error that I have indicated above.
things I did to fix were the ff:
php artisan route:cache
php artisan route:clear
but nothing has worked.
Hoping to get an idea on how to fix this one. Thank you!