|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Cortex\Foundation\Console\Commands; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Console\ConfirmableTrait; |
|
8
|
|
|
use Cortex\Foundation\Traits\ConsoleMakeModuleCommand; |
|
9
|
|
|
use Illuminate\Database\Console\Migrations\MigrateMakeCommand as BaseMigrateMakeCommand; |
|
10
|
|
|
|
|
11
|
|
|
class MigrateMakeCommand extends BaseMigrateMakeCommand |
|
12
|
|
|
{ |
|
13
|
|
|
use ConfirmableTrait; |
|
14
|
|
|
use ConsoleMakeModuleCommand; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* The console command signature. |
|
18
|
|
|
* |
|
19
|
|
|
* @var string |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $signature = 'make:migration {name : The name of the migration.} |
|
22
|
|
|
{--module= : The name of the module.} |
|
23
|
|
|
{--create= : The table to be created.} |
|
24
|
|
|
{--table= : The table to migrate.}'; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Write the migration file to disk. |
|
28
|
|
|
* |
|
29
|
|
|
* @param string $name |
|
30
|
|
|
* @param string $table |
|
31
|
|
|
* @param bool $create |
|
32
|
|
|
* |
|
33
|
|
|
* @return void |
|
34
|
|
|
*/ |
|
35
|
|
|
protected function writeMigration($name, $table, $create): void |
|
36
|
|
|
{ |
|
37
|
|
|
$this->makeDirectory($this->getMigrationPath()); |
|
38
|
|
|
|
|
39
|
|
|
parent::writeMigration($name, $table, $create); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Build the directory for the class if necessary. |
|
44
|
|
|
* |
|
45
|
|
|
* @param string $path |
|
46
|
|
|
* |
|
47
|
|
|
* @return string |
|
48
|
|
|
*/ |
|
49
|
|
|
protected function makeDirectory($path): string |
|
50
|
|
|
{ |
|
51
|
|
|
if (! $this->laravel['files']->isDirectory($path)) { |
|
52
|
|
|
$this->laravel['files']->makeDirectory($path, 0777, true, true); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return $path; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Get migration path (either specified by '--path' or '--module' options). |
|
60
|
|
|
* |
|
61
|
|
|
* @throws \Exception |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function getMigrationPath(): string |
|
66
|
|
|
{ |
|
67
|
|
|
if (! $this->laravel->files->exists($path = $this->laravel['path'].DIRECTORY_SEPARATOR.$this->moduleName())) { |
|
|
|
|
|
|
68
|
|
|
throw new \Exception("Invalid path: {$path}"); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return $path.DIRECTORY_SEPARATOR.'database'.DIRECTORY_SEPARATOR.'migrations'; |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: