dounei5721
2015-05-31 16:36
浏览 70
已采纳

限制Laravel 5.0中任何路由的最佳方法是什么?

I want to restrict some routes of my application and only allow that to only my authenticated user.

I tried check using the auth:check() function but it doesn't seem to work.

// Route Restriction
if (Auth::check()){

    //Web Directory
    Route::get('web-directory','WebDirectoryController@index');
}

When I got to mysite/web-directory I still get 404 Error - even if I'm currently log-in.

enter image description here

What is the best way to restrict any routes in Laravel 5.0 ?

图片转代码服务由CSDN问答提供 功能建议

我想限制我的应用程序的某些路由,并且仅允许我的经过身份验证的用户。

我尝试使用 auth:check()函数进行检查,但它似乎无效。

 <  code> // Route Restriction 
if(Auth :: check()){
 
 // Web Directory 
 Route :: get('web-directory','WebDirectoryController @ index'); 
} 
    
 
 

当我到 mysite / web-directory 时,我仍然得到404错误 - 即使我现在 登录。

< p>限制Laravel 5.0中任何路由的最佳方法是什么?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dsriya5471 2015-05-31 16:47
    已采纳

    All right, so I figured out the solution to my own question.

    I restrict my routes by doing this

    // Route group
    $router->group(['middleware' => 'auth'], function() {
    
        //Web Directory
        Route::get('web-directory','WebDirectoryController@index');
    }
    

    Now, I can go to my route fine, and 404 Error will only kick in when the user is not yet log-in.

    I hope this help someone.

    评论
    解决 无用
    打赏 举报
查看更多回答(1条)

相关推荐 更多相似问题