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 ?

  • 写回答

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条)

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理