dimanche 11 août 2019

Sub-Domain Routing over rides and runs the last sub domain in web.php

I need to change the database configuration according to the subdomain that hits the URL. But now, all the subdomains will be overridden by the last subdomain.

I created a group of routes with subdomain and configured DB using Config::set function. This works, but always takes the last subdomain group.

Route::domain('s1.xyz.com')->group(function () {
\Config::set("database.connections.mysql", [
                'driver' => 'mysql',
        'host' => 'localhost',
        'port' => env('DB_PORT', 'xxxx'),
        'database' => 'xx',
        'username' => 'xxx',
        'password' => 'xxxx',
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null
]);
Route::resource('/', 'LoginController');
});
Route::domain('s2.xyz.com')->group(function () {
\Config::set("database.connections.mysql", [
                'driver' => 'mysql',
        'host' => 'localhost',
        'port' => env('DB_PORT', 'yyyy'),
        'database' => 'yy',
        'username' => 'yyy',
        'password' => 'yyyy',
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null
]);
Route::resource('/', 'LoginController');
});

When s1.xyz.com is given, xx database should be used and the URL should be s1.xyz.com only. But now though I give s1.xyz.com, once I hit submit button in the login form, it redirects to s2.xyz.com



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire