du7535 2015-02-05 00:31
浏览 20
已采纳

Laravel 3 Vs Laravel 4:过滤前

I have in UsersController.php

$this->beforeFilter('permission:administration');

and in my filers.php ( this is for larval 3 I want to change it to larval 4.2 equivalent)

 Route::filter('permission', function($permission)
 {
   if(!Auth::user()->permission($permission)) return App::abort(500);
 });

This code is from Laravel 3 and I am trying to make the same thing for Laravel 4.2 I am getting there folioing error :

Object of class Illuminate\Routing\Route could not be converted to string

How could I fix this , please help

  • 写回答

1条回答 默认 最新

  • dpfqy5976 2015-02-05 00:34
    关注

    This can be done in routes.php or controller.

    In the controller:

    $this->beforeFilter('permission:administration');
    

    in your routes.php file:

    Route::group(['before' => 'permission:administration'], function() {
       Route::get('my-route', 'UsersController@action');
    });
    

    or

    Route::get('my-route', ['before' => 'permission:administration', 'uses' => 'UsersController@action'])
    

    To retrieve the "administration" value:

    Route::filter('permission', function($route, $request, $permission)
     {
       if(!Auth::user()->permission($permission)) return App::abort(500);
     });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 我的b站在没有碰到屏幕的情况下偶尔会自动跳出进度条,就像在屏幕上点了一下一样,但我并没有点。而且视频进度并没有变。这可能是什么原因造成的?
  • ¥30 STK matlab python仿真
  • ¥15 关于IMageEnView 图标定位问题
  • ¥20 求解答(matlab)
  • ¥30 ffmpeg库使用过程中遇到的问题
  • ¥15 pyqt5 中python如何通过Qtwebchannel主动发消息给web前端
  • ¥15 关于HTML中title获取xml内容的问题
  • ¥15 fanuc机器人PRIO083数字信号未复原错误,如何解决?
  • ¥20 如何为现有电路板增加远程控制功能
  • ¥15 UE5打包失败,求解决