ollieread / multiauth

Laravel multi auth
441 stars 109 forks source link

Filter for multiple auth #52

Closed notflip closed 10 years ago

notflip commented 10 years ago

Hi,

Is it possible to define a filter for every auth you use? I tried the following but it's not giving the desired results. Any ideas? Thanks!

Route::filter('auth', function() { if (Auth::company()->guest()) return Redirect::guest('company'); if (Auth::admin()->guest()) return Redirect::guest('admin'); });

mikkezavala commented 10 years ago

Why don you create a new filter in regards to group your layered app,

/* Filters */
Route::filter('auth.company', function(){
    if (Auth::company()->guest()){
        return Redirect::guest('company');
    }
});
Route::filter('auth.admin', function(){
   if (Auth::admin()->guest()){
        return Redirect::guest('admin');
    }
});

/* Routes */
//Company Routes
Route::group(array('before' => 'auth.company'), function(){
    //Some cool code here
}

//Admin Routes
Route::group(array('before' => 'auth.admin'), function(){
    //Some cool code here
}
notflip commented 10 years ago

Perfect! Thank you very much! Loving this plugin

muna9595 commented 9 years ago

Hi, I want to limit the page access by admin, parent and student at the time of routing. How can I achieve that. Consider an example, suppose I don't want admin to access index page without logged in.