Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel, call filter in filter

how i can call filter in filter using laravel?

i have this filter:

Route::filter('auth', function()
{
    if (Auth::guest())
    {
        if (Request::ajax())
        {
            return Response::make('Unauthorized', 401);
        }
        else
        {
            return Redirect::guest('login');
        }
    }
});

now i create another filter called admin and i want call auth filter in this:

Route::filter('admin', function(){
    #call auth filter

    #code    
});

it's possible do that?

like image 593
user3445218 Avatar asked Jul 31 '14 14:07

user3445218


1 Answers

Using callRouteFilter() method in Illuminate\Routing\RouteFiltererInterface as @Dwight suggested:

Route::filter('admin', function ($route, $request) {
    if ($r = Route::callRouteFilter('auth', array(), $route, $request)) {
        return $r;
    }
});
like image 110
Rusty Fausak Avatar answered Sep 28 '22 06:09

Rusty Fausak