laravel throwing MethodNotAllowedHttpException
You are getting that error because you are posting to a GET
route.
I would split your routing for validate
into a separate GET
and POST
routes.
New Routes:
Route::post('validate', 'MemberController@validateCredentials');
Route::get('validate', function () {
return View::make('members/login');
});
Then your controller method could just be
public function validateCredentials()
{
$email = Input::post('email');
$password = Input::post('password');
return "Email: " . $email . " and Password: " . $password;
}
My suspicion is the problem lies in your route definition.
You defined the route as a GET
request but the form is probably sending a POST
request. Change your route definition to match the form's request method.
Route::post('/validate', [MemberController::class, 'validateCredentials']);
It's generally better practice to use named routes (helps to scale if the controller method/class changes).
Route::post('/validate', [MemberController::class, 'validateCredentials'])
->name('member.validateCredentials');
In the view, use the validation route as the form's action.
<form action="{{ route('member.validateCredentials') }}" method="POST">
@csrf
...
</form>
The problem is the you are using POST
but actually you have to perform PATCH
To fix this add
<input name="_method" type="hidden" value="PATCH">
Just after the Form::model
line
That is because you are posting data through a get method.
Instead of
Route::get('/validate', 'MemberController@validateCredentials');
Try this
Route::post('/validate', 'MemberController@validateCredentials');