I just started learning Laravel framework today.
I would like to check for user’s session globally. I put a filter in the constructor of the base class like below.
class Base_Controller extends Controller {
public function __construct() {
parent::__construct();
$this->filter('before', 'auth')->except(array('login@index'));
}
}
it works fine except that there is one problem. I would like to ignore the auth filter for the login controller. How do I do that?
I tried
except(array(“login”)), except(array(“login.index)), and except(array(“login@index”)). None of them worked
Using
$this->filter()in a controller has a different approach that doing it in theroutes.phpfile. When you use it inside a controller,except()will just accept methods of that controller.You can solve your problem creating a new controller that extends from
Base_ControllerlikeBase_Auth_Controllerthat checks for the auth filter. You could probably use theRoute::filter('before', function(){});and then justreturn;if you detect that the controller is ‘Auth’ (tip:Request::route()->controller) but you can’t definitely exclude acontroller@action.Or do something like: