• Register
0 votes
38 views

Problem :

I want to get something very basic running. I am used to the CI and now learning the Laravel 4, and their docs are not making it easy! Anyways, I want to create the login form and just make sure that the data is posted successfully by printing it in a next form. But I am getting below exception:

“Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException”

 Any help in resolving above error will be greatly appreciated.

7 5 2
3,870 points

2 Answers

0 votes

Solution :

You are facing that error as you are posting to the GET route.

I want to split your routing for validate into the separate GET and POST routes as shown below :

The New Routes:

Route::post('validate', 'MemberController@validateCredentials');
Route::get('validate', function () {
return View::make('members/login');
});

Then your controller method could just be as shown below

public function validateCredentials()
{
    $myemail = Input::post('email');
    $mypassword = Input::post('password');
    return "Email: " . $myemail . " and Password: " . $mypassword;
}

 OR

Typically the MethodNotAllowedHttpException happens only when the

route method does not match.

Suppose you have defined POST request route file, however you are sending GET request to a route.

I know above given solutions will help you in resolving all the errors.

9 7 4
38,600 points
0 votes

Solution:

You are obtaining that error since you are posting to a GET route.

I would interrput 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');
});

Thereafter your controller method could only be

public function validateCredentials()
{
    $email = Input::post('email');
    $password = Input::post('password');
    return "Email: " . $email . " and Password: " . $password;
}

My doubt is the problem lies in your route definition.

You identified the route as a GET request however the form is possibly sending a POST request. Alter your route definition.

Route::post('/validate', 'MemberController@validateCredentials');

It's usually better practice to use named routes (uses to scale in case the controller method/class changes).

Route::post('/validate', array(
    'as' => 'validate',
    'uses' => 'MemberController@validateCredentials'
));

In the form employ the following

<?php echo Form::open(array('route' => 'validate')); ?>

The issue is the you are employing POST however really you have to perform PATCH To solve this add

<input name="_method" type="hidden" value="PATCH">

Only after the Form::model line

I encountered this issue as well and the other answers here were useful, however I am using a Route::resource which takes care of GETPOST, and other requests.

In my instance I left my route as is:

Route::resource('file', 'FilesController');

And easily modified my form to submit to the store function in my FilesController

{{ Form::open(array('route' => 'file.store')) }}

This solved the issue, and I thought it was worth pointing out as a separate answer whereas several other answers point out including a new POST route. This is an option however it's not required.

That is since you are posting data through a get method.

Instead of

Route::get('/validate', 'MemberController@validateCredentials');

Attempt this

Route::post('/validate', 'MemberController@validateCredentials');

 

10 6 4
31,120 points

Related questions

0 votes
2 answers 252 views
252 views
Problem : I am facing following error while trying to login from the form: Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message The following is my route: Route::get('/', ['as' => '/', 'uses' => 'LoginController@getLogin']); Route::get('/login', ... ']); }); The following is form tag: <form class="login-form" action="{{ route('login') }}" method="post">
asked Dec 3, 2019 alecxe 7.5k points
1 vote
1 answer 119 views
119 views
Problem: I am very new to Laravel. I have recently started leaning laravel. I am using the correct email address. I have already echoed it but if I try to send it then I face the below error: "Address in mailbox given [] does not comply with RFC 2822, 3 ... send('emails.activation', $data, function($message){ $message->to($email)->subject($subject); }); ->with('title', "Registered Successfully.");
asked Jun 5 Martin K 6.6k points
0 votes
1 answer 5 views
5 views
Problem So I have following method that draws input fields according to specified value: function drawInputs() { let type = reCalcType.options[reCalcType.selectedIndex].value; let container = document.getElementById("form_inputs"); let fields = getInputsArr(type); ... validation error: P.S. Old values are correct and displayed on console.log and they initialized before calling drawInputs function
asked Sep 14 Marivoke 530 points
0 votes
0 answers 23 views
23 views
I'm applying Laravel to write a service for mobile. I am trying to figure the solution. Can someone give me the hint?
asked Sep 14 Daniel Anderson 4k points