samedi 8 janvier 2022

how to keep logged in user to try.com domain from buy.try.com using the same database but different location in Laravel 5?

I have users tables in my database

public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('email')->unique();
            $table->string('password');
            $table->string('slug');
            $table->text('token');
            $table->enum('user_type', ['1', '2'])->default('1');
            $table->boolean('is_authenticated')->default(false);
            $table->rememberToken();
            $table->timestamps();
        });
    }

They are all connected to the same database but the diffrents folder location. So, when I want to login to try.com, I want also the same user to be login on buy.try.com.

This is the session code of try.com on config->session.php

'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 120,
'expire_on_close' => false,
'cookie' => 'try_session',
'domain' => env('SESSION_DOMAIN', 'try.com'),
'secure' => env('SESSION_SECURE_COOKIE', true), //because I'm using https ssl
'http_only' => null,

And this is the session code of buy.try.com on config->session.php

'driver' => env('SESSION_DRIVER', 'file'),
'lifetime' => 120,
'expire_on_close' => false,
'cookie' => 'try_session',
'domain' => env('SESSION_DOMAIN', 'buy.try.com'),
'secure' => env('SESSION_SECURE_COOKIE', true), //because I'm using https ssl
'http_only' => null,

Then this is .env of try.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=try_db
DB_USERNAME=try_user
DB_PASSWORD=try123

COMMON_DB_DATABASE=try_db
COMMON_DB_USERNAME=try_user
COMMON_DB_PASSWORD=try123
COMMON_DB_SOCKET=

Then this is .env of buy.try.com

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=try_db
DB_USERNAME=try_user
DB_PASSWORD=try123

COMMON_DB_DATABASE=try_db
COMMON_DB_USERNAME=try_user
COMMON_DB_PASSWORD=try123
COMMON_DB_SOCKET=

At the end they are all using the common_database to get session session

'common_database' => [
            'driver' => 'mysql',
            'url' => env('COMMON_DATABASE_URL'),
            'host' => env('COMMON_DB_HOST', '127.0.0.1'),
            'port' => env('COMMON_DB_PORT', '3306'),
            'database' => env('COMMON_DB_DATABASE','forge'),
            'username' => env('COMMON_DB_USERNAME','forge'),
            'password' => env('COMMON_DB_PASSWORD', ''),
            'unix_socket' => env('COMMON_DB_SOCKET',''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 
            ]) : [],
        ],

Can you help me to fix it ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire