Laravel modules with Tenancy for laravel #2077
Replies: 1 comment
-
To ensure that migrations from specific modules are only executed on the tenant database (and not on the main database) when using nWidart/laravel-modules with Tenancy for Laravel, you can consider these approaches without modifying the migration files inside the modules: Tagging Migrations or Naming Convention Custom Migration Command in Tenancy 'migrations_paths' => [
database_path('migrations/tenant'),
base_path('Modules/Blog/Database/Migrations/tenant'),
// ...add other paths as needed
], This way, when you run artisan tenants:migrate, only these migrations will be executed. Skip Migration on Main Database Customize the Module Service Provider (Optional) Example Implementation: // In your module's service provider
public function boot()
{
if (tenancy()->check()) {
$this->loadMigrationsFrom(__DIR__.'/../Database/Migrations/tenant');
}
} Make sure tenancy()->check() is a helper to detect whether the current context is a tenant. Tips: Avoid modifying migration files directly. You can manage which migrations are loaded based on their paths and registration logic. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
How can I set up that migration for specific module will be migrated only for tenant database. I can set up behavior that is loading it on tenant (in config of tenancy), but I can't skip migrations for main database without changes directly in modules.
Beta Was this translation helpful? Give feedback.
All reactions