PHPackages                             pbmedia/laravel-single-session - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. pbmedia/laravel-single-session

AbandonedArchivedLibrary[Authentication &amp; Authorization](/categories/authentication)

pbmedia/laravel-single-session
==============================

Prevent a User from being logged in more than once

2.0.0(7y ago)1021.8k10[1 issues](https://github.com/protonemedia/laravel-single-session/issues)MITPHPPHP ^7.1

Since Nov 20Pushed 7y ago1 watchersCompare

[ Source](https://github.com/protonemedia/laravel-single-session)[ Packagist](https://packagist.org/packages/pbmedia/laravel-single-session)[ Docs](https://github.com/pascalbaljetmedia/laravel-single-session)[ RSS](/packages/pbmedia-laravel-single-session/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (8)Dependencies (8)Versions (10)Used By (0)

Laravel Single Session
======================

[](#laravel-single-session)

[![Latest Version on Packagist](https://camo.githubusercontent.com/865704f043c7b73c7e3abdce84b469c6105d7aa2e33e89a1c220612a10a649ea/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f70626d656469612f6c61726176656c2d73696e676c652d73657373696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pbmedia/laravel-single-session)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/62cc3d2c5dba5ea110fc5a55c607d79ed2eca8f857d56c472097dc842c150598/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f70617363616c62616c6a65746d656469612f6c61726176656c2d73696e676c652d73657373696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/pascalbaljetmedia/laravel-single-session)[![Quality Score](https://camo.githubusercontent.com/d341df613e3e380ae63a3ed96df9a740ba53749bc5c0e9841b4bc09d08dfce48/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f70617363616c62616c6a65746d656469612f6c61726176656c2d73696e676c652d73657373696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/pascalbaljetmedia/laravel-single-session)[![Total Downloads](https://camo.githubusercontent.com/bd46e02fa62b9ae9bf8a5226dfa75859e96e6edc44c5f7f724d85d75e06ab057/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f70626d656469612f6c61726176656c2d73696e676c652d73657373696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/pbmedia/laravel-single-session)

This package prevents a User from being logged in more than once. It destroys the previous session when a User logs in and thereby allowing only one session per user. It assumes you use Laravel's [Authentication](https://laravel.com/docs/5.6/authentication) features.

Requirements
------------

[](#requirements)

- Laravel 5.6 only, 7.1 and 7.2 supported.
- Support for [Package Discovery](https://laravel.com/docs/5.6/packages#package-discovery).
- Support for [Laravel Passport](https://laravel.com/docs/5.6/passport).

Notes
-----

[](#notes)

- Laravel 5.6.14 and later supports [invalidating sessions out-of-the-box](https://laravel.com/docs/5.6/authentication#invalidating-sessions-on-other-devices).
- If you're still using Laravel 5.5, please use version 1.2.0.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require pbmedia/laravel-single-session
```

Publish the database migration and config file using the Artisan CLI tool.

```
php artisan vendor:publish --provider="Pbmedia\SingleSession\SingleSessionServiceProvider"
```

The database migration adds a `session_id` field to the `users` table. Run the migration to get started!

```
php artisan migrate
```

Now add the `\Pbmedia\SingleSession\Middleware\VerifyUserSession` middleware to the routes you want to protect.

Usage
-----

[](#usage)

Since Laravel 5.5 has support for Package Discovery, you don't have to add the Service Provider to your `app.php` config file.

In the `single-session.php` config file you can specify a `destroy_event`. This event will get fired once a previous session gets destroyed. You might want to use this to [broadcast](https://laravel.com/docs/5.6/broadcasting) the event and handle the destroyed session in the user interface. The constructor of the event can take two parameters, The User model and ID of the destroyed session. Here is an example event:

```
