Laravel5 Inactivity idle session logout

In this post, I would like to show how to automatically log out the user after some period of inactivity. Session timeout or Session expire depends on the server configuration so in order to achieve our target we are going to write middleware in the Laravel5. Without making any changes to server configurations we will use last activity time to log out the user.

Open your config/session.php and specify the number of minutes that you wish the session to be allowed to remain idle before it expires.

automatically logout user after some period of inactivity
Create a file called SessionDataCheckMiddleware.php in App\Http\Middleware location and copy past below code.

Now open \app\Http\Kernel.php file, add our custom “SessionDataCheckMiddleware” middleware

That is it.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.