Laravel身份验证无法正常运行

时间:2016-07-07 12:19:01

标签: php laravel session authentication

我创建了登录表单并为网站管理员端实施了身份验证。

登录表单工作得很好,但是我可以在没有记录的情况下访问admin / index。我尝试过中间件,但即使我登录它也不会让我达到管理员/索引。我错过了什么 ?

这是我的路线,

Route::group(['prefix' => 'admin'], function () {
   Route::group(['middleware' => 'auth'], function () {
   Route::get('index', array('as' => 'admin', 'uses' => 'AdminController@admin'));
   Route::get('doctors', array('as' => 'doctors.index', 'uses' => 'DoctorsController@index'));
   Route::post('doctorstore', array('as' => 'doctors.store', 'uses' => 'DoctorsController@store'));
   Route::post('doctorsmail', array('as' => 'doctors.mail', 'uses' => 'DoctorsController@update'));
});

Route::get('/', array('as' => 'getlogin', 'uses' =>'AdminController@getLogin'));
Route::post('/', array('as' => 'postlogin', 'uses' =>'AdminController@postLogin'));

这是我的控制器

public function getLogin()
     return view('admin.login');

public function postLogin(Request $request){

    if (Auth::attempt(['email' => Request::input('email'), 'password' => Request::input('password')])){
        return redirect()->route('admin');
    }else{
        return 'not entered ';
    }
}

public function getRegister()
{
    return view('admin.register');
}

protected function postRegister(Request $request)
{
    return User::create([
        'email' => $request['email'],
        'password' => bcrypt($request['password']),
    ]);
}

1 个答案:

答案 0 :(得分:0)

您永远不会关闭路线组:

Route::group(['prefix' => 'admin'], function () {
   Route::group(['middleware' => 'auth'], function () {
       Route::get('index', array('as' => 'admin', 'uses' => 'AdminController@admin'));
       Route::get('doctors', array('as' => 'doctors.index', 'uses' => 'DoctorsController@index'));
       Route::post('doctorstore', array('as' => 'doctors.store', 'uses' => 'DoctorsController@store'));
       Route::post('doctorsmail', array('as' => 'doctors.mail', 'uses' => 'DoctorsController@update'));
   }); // You were missing this
});