Skip to content

Commit 126c7a2

Browse files
committed
Add migrations to modules
1 parent 1544bea commit 126c7a2

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/Commands/MakeModule.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
class MakeModule extends \Illuminate\Console\Command implements SelfHandling
99
{
1010

11-
protected $signature = 'modules:make
12-
{id : the ID of the module. Should be unique across modules}
11+
protected $signature = 'make:module
12+
{id : the ID of the module. Should be unique across modules}
1313
{name : the display name of the module}
1414
{--url= : the URL/route-names part for the module}
1515
';
@@ -58,6 +58,7 @@ public function handle()
5858

5959
$this->makeDirectory($path);
6060
$this->makeDirectory("{$path}Views");
61+
$this->makeDirectory("{$path}Migrations");
6162
$this->makeDirectory("{$path}Models");
6263
$this->makeDirectory("{$path}Http{$ds}Controllers");
6364
$this->copyStub("Module.php.stub", "{$path}{$className}.php", $stubData + []);

src/ServiceProvider.php

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
/**
34
* Created by PhpStorm.
45
* User: Muhannad Shelleh <muhannad.shelleh@live.com>
@@ -13,21 +14,19 @@
1314
use ItvisionSy\Laravel\Modules\Commands\InitiateDatabaseTable;
1415
use ItvisionSy\Laravel\Modules\Commands\MakeModule;
1516

16-
class ServiceProvider extends BaseServiceProvider
17-
{
17+
class ServiceProvider extends BaseServiceProvider {
1818

1919
/**
2020
* Register the service provider.
2121
*
2222
* @return void
2323
*/
24-
public function register()
25-
{
24+
public function register() {
2625

2726
//copy config and views to app locations
2827
$this->publishes([
2928
__DIR__ . join(DIRECTORY_SEPARATOR, ['', '..', 'config', 'published.php']) => config_path('modules.php')
30-
//@TODO:allow publishing and reading the stubs for overriding
29+
//@TODO:allow publishing and reading the stubs for overriding
3130
]);
3231

3332
//registers console commands
@@ -39,8 +38,7 @@ public function register()
3938
}
4039
}
4140

42-
public function boot()
43-
{
41+
public function boot() {
4442

4543
//merge the config
4644
$this->mergeConfigFrom(__DIR__ . join(DIRECTORY_SEPARATOR, ['', '..', 'config', 'defaults.php']), 'modules');
@@ -64,7 +62,22 @@ public function boot()
6462
$module->registerViewsPath($this->app);
6563
}
6664
}
65+
if (($moduleMigrationsPath = $module->migrationsPath())) {
66+
$this->thisLoadMigrationsFrom($moduleMigrationsPath);
67+
}
68+
}
69+
}
70+
71+
protected function thisLoadMigrationsFrom($path) {
72+
if (method_exists($this, 'loadMigrationsFrom')) {
73+
$this->loadMigrationsFrom($path);
74+
} else {
75+
$this->app->afterResolving('migrator', function ($migrator) use ($paths) {
76+
foreach ((array) $paths as $path) {
77+
$migrator->path($path);
78+
}
79+
});
6780
}
6881
}
6982

70-
}
83+
}

0 commit comments

Comments
 (0)