【发布时间】:2015-08-06 09:10:22
【问题描述】:
我在 routes.php 中进行身份验证,这不是正确的方法。
现在我正在UserController 中进行身份验证。我遇到了问题。
在routes.php 中,我按照以下方式执行此操作。
Route::post('/login',function(){
$cred = Input::only('username','password');
if(Auth::attempt($cred)){
return Redirect::intended('/');
}else{
$error = "Username or password is incorrect.";
return Redirect::to('login', compact('error'));
}
});
Route::get('/', ['middleware' => 'auth', function(){
return view('index');
}]);
现在我正在使用控制器UserController。
class UserController extends Controller
{
public function index()
{
Route::post('/login',function(){
$cred = Input::only('username','password');
if(Auth::attempt($cred)){
return Redirect::intended('/');
}else{
$error = "Username or password is incorrect.";
}
});
}
现在在routes.php:
Route::get('index', ['middleware' => 'auth', 'uses' => 'UserController@index']);
但是下面的代码会报错:
MethodNotAllowedHttpException in RouteCollection.php line 201:
【问题讨论】:
标签: php laravel authentication laravel-5