Laravel 5在身份验证后重定向到登录页面而不是仪表板

时间:2016-02-19 07:40:59

标签: laravel-5.1

我有这个问题,我的应用程序应该将用户重定向到路由受保护的管理区域(具有中间身份验证)。当我登录时,它会再次重定向到登录页面,但是当将仪表板路径放在路径组之外时,它表现良好。可能是什么问题?这是我的代码:

  

登录后受保护路由的代码(不起作用)   

Route::get('backend/dashboard', array('as'=>'dashboard', 'uses'=>'BackendDashboardController@getDashboard'));
  

位于路线组外的仪表板路线代码(登录后运行良好)

protected function postLogin() {
        $request = Input::all();
        $user = array(
            'email' => $request['email'],
            'password' => $request['password']
        );
        if ($this->auth->attempt($user)) {
            return redirect(route('dashboard'));

        }else{
            return redirect(route('login'));
        }
    }
  

验证控制器 - 登录后功能

//Api controller 
[HttpGet]
        public int GetSelectedStockUsers(long StockId)
        {
            return 10;
        }

// Js code
 $scope.getSelectedStockUsers = function () {
            debugger;
            Stock.getStockUsers({ stockId: $scope.selectedStock.id }, function (res) {
                debugger;
            })
        }

我真的想保护我的管理路由并将所有这些路由放在auth中间件下。亲切的avice

1 个答案:

答案 0 :(得分:0)

它只重定向,如果你没有授权/登录,否则它可以正常工作。 而且我认为你遗漏了Route::group()中的某些内容,你还需要提及前缀,例如

Route::group(['prefix'=>'backend', 'middleware'=>'auth'], function(){ 
   Route::get('dashboard', array('as'=>'dashboard', 'uses'=>'BackendDashboardController@getDashboard')); 
});

<强>被修改

还尝试更新您的尝试方法,然后尝试,例如:

    if (Auth::attempt(['email' => $email, 'password' => $password])) {
        // Authentication passed...
        return redirect()->intended('dashboard');
    }