Skip to content

Commit 0668920

Browse files
committed
put back
1 parent c9d873a commit 0668920

File tree

3 files changed

+14
-28
lines changed

3 files changed

+14
-28
lines changed

config/laravel-automatic-migrations.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,6 @@
22

33
return [
44

5-
/*
6-
|--------------------------------------------------------------------------
7-
| Model Paths
8-
|--------------------------------------------------------------------------
9-
|
10-
| This value is the paths to your model files. These paths are used by the
11-
| command in order to fetch the contents of the migration methods in each
12-
| model. Specify multiple paths using an array.
13-
|
14-
*/
15-
16-
'model_paths' => app_path('Models'),
17-
185
/*
196
|--------------------------------------------------------------------------
207
| Stub Path

resources/stubs/Model.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function migration(Blueprint $table)
2424
public function definition(Generator $faker)
2525
{
2626
return [
27-
'name' => $faker->word,
27+
'name' => $faker->name,
2828
'created_at' => $faker->dateTimeThisMonth,
2929
];
3030
}

src/Commands/MigrateAutoCommand.php

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use Illuminate\Console\Command;
66
use Doctrine\DBAL\Schema\Comparator;
7-
use Illuminate\Support\Arr;
87
use Illuminate\Support\Facades\Schema;
98
use Illuminate\Support\Facades\Artisan;
109
use Illuminate\Database\Schema\Blueprint;
@@ -47,22 +46,22 @@ private function runTraditionalMigrations()
4746

4847
private function runAutomaticMigrations()
4948
{
50-
$paths = Arr::wrap(config('laravel-automatic-migrations.model_paths'));
51-
$finder = new Finder;
49+
$path = app_path('Models');
50+
$namespace = app()->getNamespace();
5251

53-
foreach ($paths as $path) {
54-
if (!is_dir($path)) {
55-
continue;
56-
}
57-
58-
foreach ($finder->in($path) as $file) {
59-
preg_match('/namespace (.*);/', $file->getContents(), $matches);
52+
if (!is_dir($path)) {
53+
return;
54+
}
6055

61-
$class = str_replace('.php', '', $matches[1] . '\\' . $file->getFilename());
56+
foreach ((new Finder)->in($path) as $model) {
57+
$model = $namespace . str_replace(
58+
['/', '.php'],
59+
['\\', ''],
60+
Str::after($model->getRealPath(), realpath(app_path()) . DIRECTORY_SEPARATOR)
61+
);
6262

63-
if (method_exists($class, 'migration')) {
64-
$this->migrate($class);
65-
}
63+
if (method_exists($model, 'migration')) {
64+
$this->migrate($model);
6665
}
6766
}
6867
}

0 commit comments

Comments
 (0)