How can I handle subdomains with one laravel installation
Ad
I am creating a laravel project for which I need one laravel installation and use its instance in sub-domain with separate database. And those separate database's info will not be in config/database.php. It will get from master database and then reconnected to the other database.
I didn't find any proper way to do this.
Do you have any idea on this ?
Thanks for your time.
Ad
Answer
Ad
Laravel supports multiple Database connections. Firstly, define the connections in config/database.php
:
<?php
return array(
'default' => 'default_connection',
'connections' => array(
// domain.com
'default_connection' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'primary_database',
'username' => 'username',
'password' => 'password'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
// sub.domain.com
'subdomain_connection' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'secondary_database',
'username' => 'username',
'password' => 'password'
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
);
Now to specify which connection your models should use you can set the $connection
property in your models:
<?php
class YourModel extends Eloquent {
protected $connection = 'subdomain_connection';
}
You can set the value of $connection
programatically.
Ad
source: stackoverflow.com
Related Questions
Ad
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad