-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_settings_table.stub
executable file
·72 lines (63 loc) · 2.22 KB
/
create_settings_table.stub
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
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSettingsTable extends Migration
{
protected $conn;
protected $table;
protected $key;
protected $value;
protected $scope;
protected $morphTable;
protected $morphEntity;
protected $morphKey;
protected $morphValue;
/**
* CreateSettingsTable constructor.
*/
public function __construct()
{
$this->conn = config('settings.stores.database.connection');
$this->table = config('settings.stores.database.names.settings.table');
$this->key = config('settings.stores.database.names.settings.key');
$this->value = config('settings.stores.database.names.settings.value');
$this->scope = config('settings.stores.database.names.settings.scope');
$this->morphTable = config('settings.stores.database.names.settings_models.table');
$this->morphEntity = config('settings.stores.database.names.settings_models.entity');
$this->morphKey = config('settings.stores.database.names.settings_models.key');
$this->morphValue = config('settings.stores.database.names.settings_models.value');
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection($this->conn)->create($this->table, function(Blueprint $table)
{
$table->string($this->scope);
$table->string($this->key);
$table->text($this->value)->nullable();
$table->primary([$this->scope, $this->key]);
});
Schema::connection($this->conn)->create($this->morphTable, function(Blueprint $table)
{
$table->morphs($this->morphEntity);
$table->string($this->morphKey);
$table->text($this->morphValue)->nullable();
$table->primary([$this->morphEntity.'_id', $this->morphEntity.'_type', $this->morphKey]);
});
app('settings')->clearCache();
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::connection($this->conn)->dropIfExists($this->table);
Schema::connection($this->conn)->dropIfExists($this->morphTable);
}
}