Reputation: 445
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
Upvotes: 0
Views: 1283
Reputation: 1402
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']) }}
Upvotes: 1
Reputation: 2179
Instead of post use get (it can still post things but your are able to retrieve too)
Upvotes: 1
Reputation: 431
{{ 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
Upvotes: 1