php - How to configure & run multiple websites with respective databases with single Laravel code instance -
i have scenario want implement in laravel.
i have implemented kind of approach in custom php. time, want shift websites framework (laravel).
i have multiple domains different regions implemented (localization
), each domain has own database , database tables structure same data different.
now want use single laravel code instance ability connect multiple databases multiple domains , each domain has own theme files.
let suppose: have domains
1. abc.com , has database name of db_abc theme/template abc 2. xyz.com , has database name of db_xyz theme/template xyz
when abc.com
domain hit/accessed, want connect db db_abc
, load data in abc
theme/template
. similar when xyz.com
hit/accessed database connection should made db_xyz
, data should loaded theme/template
xyz
files.
please me in regard.
thank you.
first of all, need point domains single project.
after can catch
domains route group:
route::group(['domain' => 'abc.com'], function() { route::get('/', 'somecontroller@someaction'); });
to use multiple databases can use connection()
:
$users = db::connection('foo')->select(...);
if these similar websites similar structure, i'd recomment keep data in single db (and maybe in same tables).
if want use same routes sites, keep db , views configuration in config file , check current domain in middleware:
if (strpos(request()->server('http_host'), 'abc.com')) { session(['site' => 'abc']); }
and data config with:
$currentdb = config('sites.db')[session('site')]; $currentviewsdir = config('sites.views')[session('site')];
Comments
Post a Comment