• Register
0 votes
546 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', ['as' => 'login', 'uses' => 'LoginController@getLogin']);
Route::group(['middleware' => ['autheticates', 'roles']], function (){
Route::get('/logout', ['as' => 'logout', 'uses' => 'LoginController@getLogout']);
Route::get('/dashboard', ['as' => 'dashboard', 'uses' => 'DashboardController@dashboard']);
});

The following is form tag:

<form class="login-form" action="{{ route('login') }}" method="post">
7.5k points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I have gone through your post. The error is in the route which you have defined. It is the get and you should change it to post

change your route as follows:

Your route:

Route::get('/login', ['as' => 'login', 'uses' => 'LoginController@getLogin']);

Change to this route:

Route::post('/login', ['as' => 'login', 'uses' => 'LoginController@getLogin']);

action="{{ route('login') }}" # form Submit action

OR

Route::post('/', 'PostController@index');

Route::post('/posts/create', 'PostController@create');

Route::post('/posts', 'PostController@store');

Post or get..if you successfully pass post value than only use post.

OR

 

This problem genrally appears only if you have forgotten to attach the method on your form or the error in Route method.

So please confirm that you added method POST/GET in your form. And please don't forget in making the matching route as follows:

<form method="POST">

If your form has method post then make post route like below.

Route::post();

I hope you understood the method.

38.6k points
0 votes

Solution:

Error in the route you've identified. Its get and must change to post

change this

Route::get('/login', ['as' => 'login', 'uses' => 'LoginController@getLogin']);

To this

Route::post('/login', ['as' => 'login', 'uses' => 'LoginController@getLogin']);
action="{{ route('login') }}" # form Submit action
Route::post('/', 'PostController@index');

Route::post('/posts/create', 'PostController@create');

Route::post('/posts', 'PostController@store');

Post or get.in case you pass post value than use post.

View: create.blade.php

@extends('layouts.main')

@section('content')

	<h1>Create new account</h1>

    {{ Form::open(['route' => 'account-create-post']) }}
    
	    <div>
	        {{ Form::label('email', 'Email:') }}
	        {{ Form::email('email') }}
	       @if($errors->has('email')){{$errors->first('email')}}@endif
	    </div>

	    <div>
	        {{ Form::label('username', 'Username:') }}
	        {{ Form::text('username') }}
	       @if($errors->has('username')){{$errors->first('username')}}@endif
	    </div>

	    <div>
	        {{ Form::label('password', 'Password:') }}
	        {{ Form::password('password') }}
	       @if($errors->has('password')){{$errors->first('password')}}@endif
	    </div>

	    <div>
	        {{ Form::label('password_confirm', 'Confirm password:') }}
	        {{ Form::password('password_confirm') }}
	       @if($errors->has('password_confirm')){{$errors->first('password_confirm')}}@endif
	    </div>

	    <div>{{ Form::submit('Create account') }}</div>

    {{ Form::close() }}


@stop

Controller: AccountController.php

<?php

class AccountController extends BaseController {

	public function getCreate(){
		return View::make('account.create');
	}

	public function postCreate(){
		return 'Hello.';
	}

}

Routes.php

<?php

Route::get('/', array(
	'as' => 'home',
	'uses' => 'HomeController@home'
));

/*
/Unauthenticated group
*/
Route::group(array('before' => 'guest'), function(){

	/*
	/ CSRF group
	*/
	Route::group(array('before' => 'csrf'), function(){

		/*
		/ Create account (POST)
		*/
		Route::get('/account/create', array(
			'as' => 'account-create-post',
			'uses' => 'AccountController@postCreate'
		));

	});

	/*
	/ Create account (GET)
	*/
	Route::get('/account/create', array(
		'as' => 'account-create',
		'uses' => 'AccountController@getCreate'
	));

});

 

31.7k points
edited by