Reputation: 1
I am facing a problem with setting middleware in construct().
Every time i the later one is only selected, here the auth as middleware.
due to this my admin is kicked out to login page of user.
and without middleware i am facing problem with lfm as admin is asked to login in the laravel-filemanager window (user is allowed to browse).
Below is my code : public function __construct() {
$middleware = '';
if(Session::get('user_role') == 'admin'){
$middleware = 'auth:admin';
} else {
$middleware = 'auth';
}
$this->middleware($middleware);
}
Upvotes: 0
Views: 600
Reputation: 19781
You cannot access the http request or session information in the constructor.
In previous versions of Laravel, you could access session variables or the authenticated user in your controller's constructor. This was never intended to be an explicit feature of the framework. In Laravel 5.3, you can't access the session or authenticated user in your controller's constructor because the middleware has not run yet.
Source: https://laravel.com/docs/5.3/upgrade (Upgrading To 5.3.0 From 5.2 > Controllers)
Upvotes: 0