Using HYN MULTITENANCY with Laraship

Laraship QuestionsCategory: TechnicalUsing HYN MULTITENANCY with Laraship
ryan asked 5 years ago

We already bought a MultiTenant License and would like some directions how we can integrate Laraship with Hyn MultiTenancy ( https://laravel-tenancy.com/ ). We will be hosting multiple instances of the platform under a sub-domain for each of our clients. Is this something that Laraship already supports or what modules and core components we need to integrate multi-tenancy to?

Looking forward to your reply.

Regards,

1 Answers
laraship Staff answered 5 years ago

Hello,

We will ask our development team to look into https://laravel-tenancy.com/ , however the way we imagine the esiest to implement is how its mentioned in the link below

https://laracasts.com/discuss/channels/laravel/l5-multiple-databases-based-on-subdomein?page=1

1) create master database where it has the subdomain mapping with the database nakme attached to

Table: customers

Fields: id, sub_domain, customer_database. //You can add any other fields required, like database username, password etc. I have same username and password for all the databases so I don't add it.

2) Bind your subdomain flags with this model:

// in routes.php

Route::group(['domain' => '{account}.mydomain.com'], function() {});

// in RouteServiceProvider

public function boot(Router $router)

{

parent::boot($router);

$router->bind('domain', function ($value) {

$domain= Customer::whereSubdomain($value)->first();

if ($domain) {

return $domain;

}

throw new Exception('error message');

});

}

3) Now create a ConfigServiceProvider or use CoralServiceProvider

public function register()

{

$customer = Request::route('domain'); // there are multiple ways of doing this

config([

'database.mysql.database' => $customer->customer_database, //this is because I have same username and password for all the databases. If you have different username and passwords set them too.

]);

DB::reconnect(); // this will help in reconnecting the database if the connection is already established. and import the DB facade.

}