Add your own stub placeholders
To compute a custom placeholder such as $TABLE_PREFIX$ when module:make renders stubs, create a replacement class and register it in stubs.replacements. Prerequisites: an existing Blog module, plus published and enabled stubs (complete steps 1–3 of Customise the generator stubs).
-
Generate the replacement class in
Blog.Terminal window php artisan module:make-replacement TablePrefix BlogThis creates
Modules/Blog/app/Console/Replacements/TablePrefix.php. -
Update
handle()to return the replacement value. The generated method returns the lowercase name of the module being created; append an underscore for a table prefix.Modules/Blog/app/Console/Replacements/TablePrefix.php <?phpnamespace Modules\Blog\Console\Replacements;use Nwidart\Modules\Support\ReplacementKeyCommand;class TablePrefix extends ReplacementKeyCommand{public function handle(): string{return strtolower($this->generator->getName()).'_';}} -
Register the class under the stub key in
config/modules.php. Use an uppercase token name as the key and keep the existing built-in tokens.config/modules.php 'replacements' => [// ...'scaffold/config' => ['STUDLY_NAME','TABLE_PREFIX' => \Modules\Blog\Console\Replacements\TablePrefix::class,],], -
Insert the token in the published stub.
stubs/nwidart-stubs/scaffold/config.stub <?phpreturn ['name' => '$STUDLY_NAME$','table_prefix' => '$TABLE_PREFIX$',]; -
Check the result by generating a new module and inspecting its config file.
Terminal window php artisan module:make Shopcat Modules/Shop/config/config.phpThe file contains
'table_prefix' => 'shop_',.
The returned string is inserted verbatim. For JSON stubs (module.json and composer.json), escape backslashes and quotes yourself (\\ and \"); invalid JSON aborts module:make before writing files.
Replacement classes apply only to stubs rendered by module:make (stubs.files and json), not to module:make-* generators.