public function routeNeedsRole($route, $roles, $result = null, $requireAll = true)
    {
        $filterName  = is_array($roles) ? implode('_', $roles) : $roles;
        $filterName .= '_'.substr(md5($route), 0, 6);

        $closure = function () use ($roles, $result, $requireAll) {
            $hasRole = $this->hasRole($roles, $requireAll);

            if (!$hasRole) {
                return empty($result) ? $this->app->abort(403) : $result;
            }
        };

        // Same as Route::filter, registers a new filter
        $this->app->router->filter($filterName, $closure);

        // Same as Route::when, assigns a route pattern to the
        // previously created filter.
        $this->app->router->when($route, $filterName);
    }
public function routeNeedsRole($route, $roles, $result = null, $requireAll = true)
    {
        $filterName  = is_array($roles) ? implode('_', $roles) : $roles;
        $filterName .= '_'.substr(md5($route), 0, 6);

        $closure = function () use ($roles, $result, $requireAll) {
            $hasRole = $this->hasRole($roles, $requireAll);

            if (!$hasRole) {
                return empty($result) ? $this->app->abort(403) : $result;
            }
        };

        // Same as Route::filter, registers a new filter
        $this->app->router->filter($filterName, $closure);

        // Same as Route::when, assigns a route pattern to the
        // previously created filter.
        $this->app->router->when($route, $filterName);
    }
public function routeNeedsRole ( $ route , $ roles , $ result = null , $ requireAll = true ) { $ filterName = is_array ( $ roles ) ? implode ( '_' , $ roles ) : $ roles ; $ filterName .= '_' . substr ( md5 ( $ route ) , 0 , 6 ) ; $ closure = function ( ) use ( $ roles , $ result , $ requireAll ) { $ hasRole = $ this -> hasRole ( $ roles , $ requireAll ) ; if ( ! $ hasRole ) { return empty ( $ result ) ? $ this -> app -> abort ( 403 ) : $ result ; } } ; // Same as Route::filter, registers a new filter $ this -> app -> router -> filter ( $ filterName , $ closure ) ; // Same as Route::when, assigns a route pattern to the // previously created filter. $ this -> app -> router -> when ( $ route , $ filterName ) ; }
Filters a route for a role or set of roles.

If the third parameter is null then abort with status code 403.
Otherwise the $result is returned.

@param string       $route      Route pattern. i.e: "admin/*"
@param array|string $roles      The role(s) needed
@param mixed        $result     i.e: Redirect::to('/')
@param bool         $requireAll User must have all roles

@return mixed
Filters a route for a role or set of roles .