Laravel 5身份验证后重定向到登录页面,而不是仪表板 [英] Laravel 5 Redirecting to login page after authentication instead of Dashboard

查看:82
本文介绍了Laravel 5身份验证后重定向到登录页面,而不是仪表板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have this problem, my application should redirect users to admin area whose routes are protected (have middle auth). When I login it redirects to login page again but when place the dashboard route outside the route group, it behaves well. What may be the problem? This is my code:

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

Code for protected route (does not work) after login

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

放置在路线组之外的仪表板路线的代码(登录后效果很好)

Code for dashboard route placed outside the route group (Works well after login)

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

身份验证控制器-登录后功能

Auth controller - Post login function

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'));
        }
    }

我真的很想保护我的管理路由,并将它们全部放置在身份验证中间件下.敬请谅解

I really want to protect my admin routes and place all of them under auth middleware. Kindly avice

推荐答案

仅当您未授权/登录时,它才会重定向,否则它将正常工作. 而且我认为您在Route::group()中缺少一些内容,还需要提及前缀

It only redirects, if you are not authorize/loggedin, otherwise it works fine. and I think you are missing something in Route::group() you also need to mention the prefix eg

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

已编辑

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

Also try to update your attempt method, then try it, eg:

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

这篇关于Laravel 5身份验证后重定向到登录页面,而不是仪表板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆