[11.x] Adds ServiceProvider::publishesMigrations() method
#49246
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This minimal pull request proposes the addition of a
ServiceProvider::publishesMigrations()method, which can be used in favor ofServiceProvider::publishes()for migrations. It will ensure that any published migration has an "up-to-date" date in its name.To get started, packages may opt in to this new method simply by replacing
publisheswithpublishesMigrations:$this->publishes([ __DIR__.'/../config/pennant.php' => config_path('pennant.php'), ], 'pennant-config'); - $this->publishes([ + $this->publishesMigrations([ __DIR__.'/../database/migrations' => $this->app->databasePath('migrations'), ], 'pennant-migrations');If a package wants to support multiple Laravel versions, you may use the
method_existsfunction like so:The result will be that, instead of publishing a migration with an old date, Laravel will use a new date instead:
Note, when a package contains multiple migrations, for example like Jetstream with
create_userandcreate_team_user, the package developer needs to add a number after the date. Here is an example, before and after:At the moment, and intentionally, because I wanted to ensure we discuss it before coding it, this pull request does not detect if the migration already exists. So, if you run the command
php artisan vendor:publish --provider="Laravel\Pennant\PennantServiceProvider"twice, you will end up with two similar migrations in your database/migrations directory: