Reputation: 5608
I want to protect the index page from direct access. And also want to restrict direct access for /
.
The problem is when i enter the correct credentials for login it throws and error MethodNotAllowedHttpException in RouteCollection.php line 201:
.
And that error comes up when i enter the wrong credentials for login also.
My routes.php code is
Route::get('index', array(
'before' => 'auth',
function(){
return view('login');
}));
Route::get('/login', function(){
return view('login');
});
Route::post('/login',function(){
$cred = Input::only('username','password');
if(Auth::attempt($cred)){
return Redirect::intended('index');
};
return Redirect::to('/login');
});
Route::get('/logout', function(){
Auth::logout();
return view('logout');
});
Route::get('/register', function(){
return view('register');
});
Route::post('/register',function(){
$user = new \App\User;
$user->username = input::get('username');
$user->email = input::get('email');
$user->password = Hash::make(input::get('username'));
$user->designation = input::get('designation');
$user->save();
$theEmail = Input::get('username');
return view('thanks')->with('theEmail',$theEmail);
});
Upvotes: 0
Views: 186
Reputation: 1
MethodNotAllowedHttpException shows up when you are posting to a get route from your form, or vice versa. Could you check that your login form's method is set to POST.
Upvotes: 0
Reputation: 4167
In laravel 5,
['before' => 'auth']
is deprecated. But instead, you should use
['middleware' => 'auth']
For more information about middleware in laravel click here
Upvotes: 1