nWidart / laravel-modules

Module Management In Laravel
https://docs.laravelmodules.com
MIT License
5.57k stars 970 forks source link

Artisan migration issues #1943

Closed shawe closed 2 months ago

shawe commented 2 months ago

Versions:

Description:

I have 5 laravel modules installed, but only 2 enabled. When I run php artisan migrate, the disabled modules migration are also called but it must not be called because they are not enabled.

This are causing issues like don't allow to migrate correctly the enabled modules if other disabled modules for example have issues.

To mitigate this problem on module ServiceProvider:

    public function boot(): void
    {
        $module = Module::find($this->moduleNameLower);
        if ($module->isEnabled()) {
            //
        }
    }

    public function register(): void
    {
        $module = Module::find($this->moduleNameLower);
        if ($module->isEnabled()) {
            $this->app->register(RouteServiceProvider::class);
            ...
        }
    }

I don't now if this may be necessary on some other functions, but at least, with for me is not registering:

Have sense for you that this may be the default behavior? Maybe an intermediate class to extends on laravel modules, that takes care of doing this by default, and not loading things that are not enabled.

I now that I can implement this on my own code, I'm only suggesting that I think that this have sense for me to be the default behavior.

alissn commented 2 months ago

Hi @shawe,

The pull request #1945 addresses your issue. To disable the auto-registration of migrations and register them manually, please update your config to the latest version (some new keys have been added). Set the modules.auto-discover.translations option to false in your configuration.

Reference:
https://github.com/nWidart/laravel-modules/blob/27d90b2713497c60616cde7440d1065542fdd59e/config/config.php#L180-L201