Skip to content

Commit 3d2255f

Browse files
Fix migration file extension when publishing from Package
When Package has registered migrations to publish, resulting migration file being published without '.php' file extension. In order to get Migration discovered and available to run, file should be properly named in the form of 'Y_m_d_His_migration_file_name_here.php' and should have '.php' extension.
1 parent 6cc0f67 commit 3d2255f

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

src/PackageServiceProvider.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Spatie\LaravelPackageTools;
55

66
use Illuminate\Support\ServiceProvider;
7+
use Illuminate\Support\Str;
78
use ReflectionClass;
89
use Spatie\LaravelPackageTools\Exceptions\InvalidPackage;
910

@@ -54,7 +55,7 @@ public function boot()
5455
foreach ($this->package->migrationFileNames as $migrationFileName) {
5556
if (! $this->migrationFileExists($migrationFileName)) {
5657
$this->publishes([
57-
$this->package->basePath("/../database/migrations/{$migrationFileName}.php.stub") => database_path('migrations/' . now()->format('Y_m_d_His') . '_' . $migrationFileName),
58+
$this->package->basePath("/../database/migrations/{$migrationFileName}.php.stub") => database_path('migrations/' . now()->format('Y_m_d_His') . '_' . Str::finish($migrationFileName, '.php')),
5859
], "{$this->package->name}-migrations");
5960
}
6061
}

tests/PackageServiceProviderTests/PackageMigrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@ public function it_can_publish_the_migration()
2323
->artisan('vendor:publish --tag=laravel-package-tools-migrations')
2424
->assertExitCode(0);
2525

26-
$this->assertFileExists(database_path('migrations/2020_01_01_000000_create_laravel_package_tools_table'));
26+
$this->assertFileExists(database_path('migrations/2020_01_01_000000_create_laravel_package_tools_table.php'));
2727
}
2828
}

0 commit comments

Comments
 (0)