nWidart / laravel-modules

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

How can i Vendor:publish in a module #1938

Open redtusker opened 1 month ago

redtusker commented 1 month ago

unable to vendor publish config and assets and there is no command way to do so

i.e want to run the following but its not working there is no commands for module to do so

php artisan vendor:publish --provider="Spatie\WebhookServer\WebhookServerServiceProvider"

alissn commented 1 month ago

Hi,

To publish configuration files, you can use the following command:

php artisan module:publish-config

To publish assets, use this command:

php artisan module:publish

Both commands support the --all option to publish for all modules. You can also specify multiple module names like this:

php artisan module:publish-config Base User Tag

for publish package config,vite-loader and stubs :

php artisan vendor:publish --provider="Nwidart\Modules\LaravelModulesServiceProvider"
redtusker commented 1 month ago

Hi, thanks for replying

I tried those commands but it didn't work the config and migrations are not published

image

alissn commented 1 month ago

ensure you module contain this function on provider and call on boot method. and path is correct.

    /**
     * Register config.
     */
    protected function registerConfig(): void
    {
        $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
        $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
    }

reference on module sutb: https://github.com/nWidart/laravel-modules/blob/15dec6bed2826feba9012a59bf08f880ecc9ba7d/src/Commands/stubs/scaffold/provider.stub#L74-L81

redtusker commented 1 month ago

Yes the module contain this function on the provider

protected function registerConfig(): void
    {
        $this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
        $this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
    }
redtusker commented 1 month ago

but still its not working as expected and still unable to publish those files