Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

louischappell's avatar

1 concurrent user

I'm pretty new to laravel, but have done the scratch series and made a few projects.

I would like 1 concurrent user, something I think should be standard?! I have tried using this method: https://www.jesusamieiro.com/limit-one-session-per-user-in-laravel-5/

I did the steps on a clean project, only with make:auth, I didn't delete any of the logincontroller, only pasted the sendLoginResponse method at the top of the class.

No success. In chrome, it keeps my session even if private browsing, when I try to login using firefox, it fails giving this error:

Argument 1 passed to App\Http\Controllers\Auth\LoginController::sendLoginResponse() must be an instance of App\Http\Controllers\Auth\Request, instance of Illuminate\Http\Request given, called in .....\test\vendor\laravel\framework\src\Illuminate\Foundation\Auth\AuthenticatesUsers.php on line 45

if I refresh the page it allows me to login.

Is there a guide to do this from a clean project as I don't understand where I'm going wrong.

Thanks in advance!

0 likes
3 replies
tisuchi's avatar

Have you tried this?

public function swapping($user) {
    $new_sessid   = \Session::getId(); //get new session_id after user sign in
    $last_session = \Session::getHandler()->read($user->last_sessid); // retrive last session

    if ($last_session) {
        if (\Session::getHandler()->destroy($user->last_sessid)) {
            // session was destroyed
        }
    }

    $user->last_sessid = $new_sessid;
    $user->save();
}

Ref: https://stackoverflow.com/questions/27938186/laravel-only-allowing-one-session-per-user-at-a-time

4 likes
louischappell's avatar
louischappell
OP
Best Answer
Level 2

I couldn't interpret the error, though now it seems readable... If anyone else has the problem and is new, add:

use Illuminate\Http\Request;

In your LoginController, it was trying to use the App... in the error rather than illuminate...

Also worth noting, the instance in which the user registers is not counted. They could theoretically keep that session active indefinitely.

louischappell's avatar

@tisuchi, thanks for the suggestion, I did try that, although wasn't sure how to implement it and failed miserably. I tried it a few ways, using the method you suggested, do I need to add that as a new column in the user database or just in the User.php file? Should the code suggested in the stackoverflow thread be placed in the LoginController? How is the method 'swapping' triggered?

If that's the suggested way to tackle this situation (it looks a lot neater) I'll try until I can do it that way.

Please or to participate in this conversation.