diff --git a/src/Illuminate/Foundation/Console/StubPublishCommand.php b/src/Illuminate/Foundation/Console/StubPublishCommand.php index e2a293d489db..554d81609fe7 100644 --- a/src/Illuminate/Foundation/Console/StubPublishCommand.php +++ b/src/Illuminate/Foundation/Console/StubPublishCommand.php @@ -17,7 +17,8 @@ class StubPublishCommand extends Command */ protected $signature = 'stub:publish {--existing : Publish and overwrite only the files that have already been published} - {--force : Overwrite any existing files}'; + {--force : Overwrite any existing files} + {--only= : Published stubs will be limited to files that start with the given value}'; /** * The console command description. @@ -83,6 +84,19 @@ public function handle() realpath(__DIR__.'/../../Routing/Console/stubs/middleware.stub') => 'middleware.stub', ]; + if ($this->option('only')) { + $stubs = array_filter( + $stubs, + fn ($name) => str_starts_with($name, strtolower($this->option('only'))), + ); + } + + if (count($stubs) === 0) { + $this->components->error('No stubs matched the given options.'); + + return self::FAILURE; + } + $this->laravel['events']->dispatch($event = new PublishingStubs($stubs)); foreach ($event->stubs as $from => $to) {