0
votes

I'm trying to make login form in Laravel 4.2 + Sentry . The problem is that when I submit the form I got the error that method is not allowed.

When I check my form in source it has method="POST" and also in the route I've wrote post. What can be the problem?

MethodNotAllowedHttpException

but can't see why? This is the form

        {{ Form::open(array('route' => 'check-auth')) }}
            <div class="body bg-gray">
                {{-- Display flash message --}}
                @if (Session::has('flash_message'))
                    <span style="margin-left:18%; color: #ff0000">{{ Session::get('flash_message') }}</span>
                @endif

                <div class="form-group">
                    <input type="text" name="email" class="form-control" placeholder="User email"/>
                    @if($errors->has('login_errors')) <span class="has-error">{{ $errors->first('email') }}</span> @endif
                </div>
                <div class="form-group">
                    <input type="password" name="password" class="form-control" placeholder="User password"/>
                </div>
            <button type="submit" name="submitbtn" class="btn bg-olive btn-block">Sign me in</button>  
            </div>
        {{ Form::close() }}

Route

Route::post('user-login', ['as'=>'check-auth', 'uses'=>'AuthenticationController@login']);

and controller

public function login()
{
    try{
        $credentials = array(
            'email'     => Input::get('email'),
            'password'  => Input::get('password')

        );

        $user = Sentry::authenticate($credentials, false);
        if($user){
            return Redirect::to('dashboard');
        }

        return Redirect::to('/')->with('title','Login errors');
    }
    catch(Exception $e){
        echo $e->getMessage();
        Session::flash('flash_message', 'No access!');
        return Redirect::to('/')->with('title','Login errors');
    }
}

UPDATE: Error

production.ERROR: Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException in /var/www/html/time/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php:210
3
It might be helpful to show us the exception too. - Chris
@Chris I've updated the question. This is what I see only.. - VLS
Given the code you provided, I don't see any issues. You'll have to post more code and as @Chris said, show the whole exception. - Andrei
You probably have but can you check over the basics. Correct machine (I notice the error says production), any nesting to the routes with prefixes, try redefining the route as GET and die() with some message at the top of the route action in the controller. - Chris

3 Answers

1
votes

{{ Form::open(array('route' => 'check-auth')) }}

See, You are using route check-auth and in routes file you defined a different route i.e user-login

Route::post('user-login', ['as'=>'check-auth', 'uses'=>'AuthenticationController@login']);

Correct route and try again this will work

1
votes

Instead of post use get (it can still post things but your are able to retrieve too)

1
votes

You're route is correct, the only thing I could suggest would be to append the type to the opening of the form:
{{ Form::open(['url' => 'check-auth', 'method' => 'post']) }}