Search code examples
authenticationyii2laravel-5.3yii2-advanced-app

Common authentication table between Yii2 advance and Laravel 5.3


I have already one application built using Yii2 advance and working perfectly.

Now, client's requirement is to create new separate (but related with first) application using Laravel 5.3 and this new system must use the same database of Yii2.

A user should be able to login into both the application.

So, I'm curious is it even possible?

Any help would be appreciated.

Thanks,

Parth vora


Solution

  • Finally, I am able to achieve what I wanted.

    So, here are the steps you need follow in your Laravel in order to login into Laravel application using auth table of Yii2:

    • Yii2 uses "user" name for the auth table, whereas Laravel uses "users". So add this into your User model:

      protected $table = "user";

    • Yii2 uses "password_hash" field to store the user password, whereas Laravel uses "password". So add this into your User model:

      public function getAuthPassword()
      {
          return $this->password_hash;
      }
      
    • Yii2 uses "auth_key" field to store the user's remember token, whereas Laravel uses "remember_token". You also need to increase size of this field from 32 to 100, otherwise you will get an error upon logout. So add this into your User model:

      public function getRememberTokenName()
      {
          return 'auth_key';
      }
      

      You also need to increase the size of 'auth_key' field from 32 to 100, otherwise you will get an error upon logout.

    • Yii2 uses "int(11)" for created_at and updated_at field type, whereas Laravel uses "timestamp" type. So add this into your User model:

      protected $dateFormat = 'U';

    Hope it might helpful to someone.

    Thanks