1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Glorand\Model\Settings\Console; |
4
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
6
|
|
|
use Illuminate\Filesystem\Filesystem; |
7
|
|
|
use Illuminate\Support\Facades\Schema; |
8
|
|
|
use Illuminate\Support\Str; |
9
|
|
|
|
10
|
|
|
class CreateSettingsTable extends Command |
11
|
|
|
{ |
12
|
|
|
/** @var string */ |
13
|
|
|
protected $signature = 'model-settings:model-settings-table'; |
14
|
|
|
|
15
|
|
|
/** @var string */ |
16
|
|
|
protected $description = 'Create migration for the settings table'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param \Illuminate\Filesystem\Filesystem $file |
20
|
|
|
* @return bool |
21
|
|
|
* @throws \Illuminate\Contracts\Filesystem\FileNotFoundException |
22
|
|
|
*/ |
23
|
12 |
|
public function handle(Filesystem $file) |
24
|
|
|
{ |
25
|
12 |
|
$table = strtolower(config('model_settings.settings_table_name')); |
26
|
12 |
|
$table = Str::snake(trim($table)); |
27
|
12 |
|
if (empty($table)) { |
28
|
3 |
|
$this->error('The name of the table is required!'); |
29
|
|
|
|
30
|
3 |
|
return 1; |
31
|
|
|
} |
32
|
|
|
|
33
|
9 |
|
if (Schema::hasTable($table)) { |
34
|
3 |
|
$this->error('Table "' . $table . '" already exists!'); |
35
|
|
|
|
36
|
3 |
|
return 2; |
37
|
|
|
} |
38
|
|
|
|
39
|
6 |
|
$fileName = date('Y_m_d_His') . '_create_' . $table . '_table.php'; |
40
|
6 |
|
$path = database_path('migrations') . '/' . $fileName; |
41
|
6 |
|
$className = 'Create' . ucfirst(Str::camel($table)) . 'Table'; |
42
|
|
|
|
43
|
|
|
|
44
|
6 |
|
$stub = $file->get(__DIR__ . '/../../stubs/create_settings_table.stub'); |
45
|
6 |
|
$stub = str_replace('DummyClass', $className, $stub); |
46
|
6 |
|
$stub = str_replace('DummyTable', $table, $stub); |
47
|
|
|
|
48
|
6 |
|
$file->replace($path, $stub); |
49
|
6 |
|
$this->line("<info>Created Migration:</info> {$fileName}"); |
50
|
|
|
|
51
|
6 |
|
return 0; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|