I have a scenario where I am putting certain information in session after user is successfully logged in. I am using Laravel 5.2. As in Laravel 5.2 you just redirect user to /login and specify protected $redirectTo variable and the rest is cared by Laravel itself. Now I want whenever user is logged in successfully, I want to put some information in session. Currently what I am doing when user is redirected to my protected $redirectTo url I put information in that like
\Session::put('user.data', $someData);
It works fine in normal scenario. But say user is logged out and tries to access some auth protected url, say example.com/showUsers saved in his browser. Now Laravel will check its a login protected url it will redirect user to login page, user is successfully logged in and Now in this case Laravel redirects the user to previous url. Now the information that I want to put in session isn't in session so I get error.
I have checked Auth/AuthController, Authication.php in middleware but don't find any place.
Currently I am putting it in /app/Http/Middleware/Authenticate.php before the last statement return $next($request); like this
if(empty(\Session::get('user.data'))) {
$someData = getSomeData();
\Session::put('user.agency', $someData);
}
return $next($request);
I don't know its a good approach or not So can any body let me know am I doing good or where do I put my session code that is executed every time user logs in.