-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleMigrationCommand.php
More file actions
59 lines (46 loc) · 1.58 KB
/
Copy pathModuleMigrationCommand.php
File metadata and controls
59 lines (46 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
class ModuleMigrationCommand extends Command
{
protected $signature = 'module:migration {module} {name}';
protected $description = 'Bir modüle migration dosyası ekler';
public function handle(): void
{
$module = Str::studly($this->argument('module'));
$name = Str::snake($this->argument('name'));
$basePath = app_path("Modules/{$module}/database/migrations");
if (!File::exists($basePath)) {
File::makeDirectory($basePath, 0755, true);
}
$timestamp = now()->format('Y_m_d_His');
$filename = "{$timestamp}_{$name}.php";
// Laravel'e uygun şekilde create_xxx_table → xxx olarak tablo ismini al
$tableName = Str::between($name, 'create_', '_table') ?: $name;
$stub = <<<PHP
<?php
use Illuminate\\Database\\Migrations\\Migration;
use Illuminate\\Database\\Schema\\Blueprint;
use Illuminate\\Support\\Facades\\Schema;
return new class extends Migration {
public function up(): void
{
Schema::create('{$tableName}', function (Blueprint \$table) {
\$table->id();
// alanlar buraya
\$table->softDeletes();
\$table->timestamps();
});
}
public function down(): void
{
Schema::dropIfExists('{$tableName}');
}
};
PHP;
File::put("{$basePath}/{$filename}", $stub);
$this->info("✅ {$module} modülüne {$filename} migration dosyası eklendi.");
}
}