dqdfpmmi022763 2013-04-07 16:45
浏览 35
已采纳

如何使用Laravels Auth方法验证对控制器的访问?

I've been reading http://codehappy.daylerees.com and getting into Laravel gradually, but I stumbled upon some confusion after trying to get authentication working.

The examples on that site in the majority use closures and basically do a lot of things I personally do in controllers inside the routes.php file. No problem, Laravel let's me use controllers and routes, however let's say I wish to restrict access to my admin panel in the routes. So don't let users go to http://example.com/admin without first authenticating. The explanations cover that, but using closures/anonymous functions. So with closures it would look like this:

Route::get('admin', array('before' => 'auth', 'do' => function() {
  // return admin view
}));

So I tried to use it the same way, but with a controller like this:

Route::get('admin', array('before' => 'auth', 'do' => 'admin_controller@index'));

Which results in a white page.

So my question is how can I forward the 'get' to a controller instead of handling it with a closure while still authenticating?

  • 写回答

1条回答 默认 最新

  • dtxob80644 2013-04-07 17:09
    关注

    Use uses instead of do

    Route::get('admin', array('before' => 'auth', 'uses' => 'admin_controller@index'));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度