Skip to content

Commit 9acd22e

Browse files
[12.x] Allow Container to build Migrator from class name (#55501)
* allow building Migrator from class name * bind Migrator * remove unneeded change * remove unneeded change * Update MigrationServiceProvider.php --------- Co-authored-by: Taylor Otwell <[email protected]>
1 parent 84753fc commit 9acd22e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/Illuminate/Database/MigrationServiceProvider.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ protected function registerMigrator()
8282

8383
return new Migrator($repository, $app['db'], $app['files'], $app['events']);
8484
});
85+
86+
$this->app->bind(Migrator::class, fn ($app) => $app['migrator']);
8587
}
8688

8789
/**
@@ -220,7 +222,7 @@ protected function registerMigrateStatusCommand()
220222
public function provides()
221223
{
222224
return array_merge([
223-
'migrator', 'migration.repository', 'migration.creator',
225+
'migrator', 'migration.repository', 'migration.creator', Migrator::class,
224226
], array_values($this->commands));
225227
}
226228
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Illuminate\Tests\Integration\Database;
4+
5+
use Illuminate\Database\Migrations\Migrator;
6+
7+
class MigrationServiceProviderTest extends DatabaseTestCase
8+
{
9+
public function testContainerCanBuildMigrator()
10+
{
11+
$fromString = $this->app->make('migrator');
12+
$fromClass = $this->app->make(Migrator::class);
13+
14+
$this->assertSame($fromString, $fromClass);
15+
}
16+
}

0 commit comments

Comments
 (0)