'Laravel - How to share the session between two or more Web Application?

I have two web Applications. I will login in to one Web Application and will navigate to another by links or redirection from the first Application. Lastly after completing some steps in Application two, I will be redirected to Application one. How can I implement this?



Solution 1:[1]

Create a new database called sessions.

Configure a connection profile for the session database secondary to your apps primary databases for both apps.

And then they should be syncing up in storing the data for sessions, being able to share them etc...

config/database.php

'app_main_database' => [
    'driver'    => env('DB_CONNECTION'),
    'host'      => env('DB_HOST'),
    'port'      => env('DB_PORT'),
    'database'  => env('DB_DATABASE'),
    'username'  => env('DB_USERNAME'),
    'password'  => env('DB_PASSWORD'),
],

'sessions_database' => [
    'driver'    => env('DB_CONNECTION_SESSION'),
    'host'      => env('DB_HOST_SESSION'),
    'port'      => env('DB_PORT_SESSION'),
    'database'  => env('DB_DATABASE_SESSION'),
    'username'  => env('DB_USERNAME_SESSION'),
    'password'  => env('DB_PASSWORD_SESSION'),
],

Configure session.connection to the name for your session driver

config/session.php

<?php

use Illuminate\Support\Str;

return [

    'driver' => env('SESSION_DRIVER', 'database'),

    'connection' => env('SESSION_CONNECTION', 'sessions_database'),

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tschallacka