Laravel 5.2: How to enable multi session per user in Sentry 2

If you are using Sentry 2 with your favourite Laravel framework then might have a single session per user which is security features. But you may need multi sessions per user. Say you have one account to allow to moderate content in your website from admin panel. And you don’t want to create multiple user account and provide to individual. Where as you want a single account so multiple Admin user can use it.
For multi session per user you need to override one of the sentry method, don’t do this inside sentry. Do it in your User model. Add the following code in your User model

 use Cartalyst\Sentry\Users\Eloquent\User as SentryUser;
class User extends SentryUser {
    // Override the SentryUser getPersistCode method.
    public function getPersistCode() {
       if (!$this->persist_code) {
           $this->persist_code = $this->getRandomString(); // Our code got hashed
           $persistCode = $this->persist_code;
           return $persistCode;
        return $this->persist_code;

Leave a Comment

Your email address will not be published. Required fields are marked *