1

I am trying to use the orchestral/tenanti package in my laravel 5 installation to get a multi database multi tenant architecture up and running but I am not sure how to proceed after the installation.

I have followed the installation instructions carefully and installed the package through composer, defined the service providers and the alias in the config/app.php file and I also went ahead ahead and edited the AppServiceProvider's boot method.

Now this section in the documentation is blurry to me. What is it supposed to mean?

And after that, how am I supposed to proceed from here on? When I try the new artisan commands that come with the package like tenanti:install and others like it I keep getting an error Driver [mysql] not supported and so on. What am I doing wrong and how to set up this package correctly and where to go after the package has been set up.

Where do I create the migration files for the main DB and where do I create the migration files for the tenant DB? And how do I use this package inside my code?

Rohan
  • 13,308
  • 21
  • 81
  • 154

1 Answers1

2

The driver here describe the unique identifier for your tenant, tenant could be based on company, team, site etc. You might even have multiple drivers in a single application.

So in order to describe a driver, you must decide how you want to structure your application, let say you decide that user can have multiple sites, and each site has it's own tenant database.

'drivers' => [
    'site' => [
        'model' => App\Site::class, \\ The eloquent model for `sites` table.
        'migration' => 'tenant_migrations',
        'path' => database_path('tenanti/site'),
    ]
],

Now assume that you have created the App\Site model, and create the observer as describe in the readme.

You can create new migration schema by using php artisan tenanti:make site create_posts_table. This command would now create a new migration schema in database/tenant/site/.

Once you have the migration, create a record through Eloquent, or manually and run php artisan tenanti:migrate site.

Problem with Multi-Database Tenant

It easy to make your database connection to swap between the default and current tenant (using migration etc), however when we want to run the migration from a command line, it not possible to dynamically swap between connection as we don't know this information (console doesn't use middleware).

To solve this, you need to setup Database Connection Resolver

crynobone
  • 1,814
  • 12
  • 22