Question

Began studying Laravel and faced problem with filters... How to turn auth filter? I wrote the following code, but it does not work:

Route::filter('auth', function() {
    if (Auth::guest()) {
        Session::put('redirect_after_login', Request::url());
        return Redirect::to('user/login/');
    }
});

Route::filter('guest', function() {

    if (Auth::check()) return Redirect::to('/login');
});

Basically Route::filter('guest' does not work

Was it helpful?

Solution

You can 'turn on' a filter by adding it to a route or route groups 'before' property. I.e.:

Route::group(array(
        'before' => 'auth'
    ), function(){

        Route::get('', array(
            'as'   => 'admin.dashboard',
            'uses' => 'DashboardController@getIndex'
        ));

        Route::post('page/contenttype/present', array(
            'uses' => 'PageController@contenttypeDataPresenter',
            'as'   => 'admin.page.contenttypedatapresenter'
        ));
});

What you did was defining a filter. You now only need to attach it to a route.

Please see this section: http://laravel.com/docs/routing#route-filters

OTHER TIPS

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top