Sitemap

How to Logout from all other devices Laravel 10 | Single Session Login in Laravel

Oct 17, 2024

In this tutorial we’re going to learn how to logout another device if login another browser then logout from another device.

First step go to Kernal.php and put below code.

\Illuminate\Session\Middleware\AuthenticateSession::class,
Press enter or click to view image in full size

Next go to Logincontroller and put the below function.

C:\xampp\htdocs\learning\testing\app\Http\Controllers\Auth\LoginController.php
 public function authenticated(Request $request){
Auth::logoutOtherDevices((request('password')));
}
Press enter or click to view image in full size

Import this class as well

use Illuminate\Http\Request;
Press enter or click to view image in full size

Next to run your project using below command.

php artisan serve
Press enter or click to view image in full size

Now if you same id login with two browser then refresh 1 browser 1 automatic logout from another devices.

--

--

Amit Kumar Thakur
Amit Kumar Thakur

Written by Amit Kumar Thakur

Hi I am Amit Experienced Web Developer with a demonstrated history of working in the information technology and services industry.

No responses yet