dscc90150010 2015-01-31 14:02
浏览 184

如果已登录,则在访问登录页面时,Laravel会重定向到用户仪表板

I have a basic login system setup, but I would like the user to be sent to there dashboard page if they try to access the "login" page or "create account" page.

How do I go about doing this?

I am thinking something in the routes file?:

Route::post('/login', array('uses' => 'UserController@login'));
Route::post('/create-account', array('uses' => 'UserController@createAccount'));

Route::group(array('before' => 'auth'), function () {
    Route::get('/dashboard', array('uses' => 'DashboardController@index'));

    Route::get('/logout', function () {
        Auth::logout();
        return Redirect::to('/start');
    });
});

Perhaps some kind of group around the first two routes?

  • 写回答

5条回答 默认 最新

  • donglunzai4288 2015-01-31 16:52
    关注

    A before filter is perfect for this. Since it basically will do the opposite of auth let's call it no_auth:

    Route::filter('no_auth', function(){
        if(Auth::check()){
            return Redirect::to('dashboard');
        }
    }
    

    And then wrap a group around your two routes to apply the filter:

    Route::group(array('before' => 'no_auth'), function(){
       Route::post('/login', array('uses' => 'UserController@login'));
       Route::post('/create-account', array('uses' => 'UserController@createAccount'));
    });
    

    Edit

    Actually, as @afarazit points out, there's already a filter like that in app/filters.php called guest. You just have to change the redirect URL to dashboard and you're ready to go.

    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序