|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Support\Str; |
|
4
|
|
|
|
|
5
|
|
|
if (!function_exists('twillIncrementsMethod')) { |
|
6
|
|
|
/** |
|
7
|
|
|
* @return string |
|
8
|
|
|
*/ |
|
9
|
|
|
function twillIncrementsMethod() |
|
10
|
|
|
{ |
|
11
|
55 |
|
return config('twill.migrations_use_big_integers') |
|
12
|
55 |
|
? 'bigIncrements' |
|
13
|
55 |
|
: 'increments'; |
|
14
|
|
|
} |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
if (!function_exists('twillIntegerMethod')) { |
|
18
|
|
|
/** |
|
19
|
|
|
* @return string |
|
20
|
|
|
*/ |
|
21
|
|
|
function twillIntegerMethod() |
|
22
|
|
|
{ |
|
23
|
55 |
|
return config('twill.migrations_use_big_integers') |
|
24
|
55 |
|
? 'bigInteger' |
|
25
|
55 |
|
: 'integer'; |
|
26
|
|
|
} |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
if (!function_exists('createDefaultFields')) { |
|
30
|
|
|
/** |
|
31
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $table |
|
32
|
|
|
* @param bool $softDeletes |
|
33
|
|
|
* @param bool $published |
|
34
|
|
|
* @param bool $publishDates |
|
35
|
|
|
* @param bool $visibility |
|
36
|
|
|
* @return void |
|
37
|
|
|
*/ |
|
38
|
|
|
function createDefaultTableFields($table, $softDeletes = true, $published = true, $publishDates = false, $visibility = false) |
|
39
|
|
|
{ |
|
40
|
55 |
|
$table->{twillIncrementsMethod()}('id'); |
|
41
|
|
|
|
|
42
|
55 |
|
if ($softDeletes) { |
|
43
|
55 |
|
$table->softDeletes(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
55 |
|
$table->timestamps(); |
|
47
|
|
|
|
|
48
|
55 |
|
if ($published) { |
|
49
|
55 |
|
$table->boolean('published')->default(false); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
55 |
|
if ($publishDates) { |
|
53
|
|
|
$table->timestamp('publish_start_date')->nullable(); |
|
54
|
|
|
$table->timestamp('publish_end_date')->nullable(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
55 |
|
if ($visibility) { |
|
58
|
|
|
$table->boolean('public')->default(true); |
|
59
|
|
|
} |
|
60
|
55 |
|
} |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if (!function_exists('createDefaultTranslationsTableFields')) { |
|
64
|
|
|
/** |
|
65
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $table |
|
66
|
|
|
* @param string $tableNameSingular |
|
67
|
|
|
* @param string|null $tableNamePlural |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
function createDefaultTranslationsTableFields($table, $tableNameSingular, $tableNamePlural = null) |
|
71
|
|
|
{ |
|
72
|
55 |
|
if (!$tableNamePlural) { |
|
73
|
55 |
|
$tableNamePlural = Str::plural($tableNameSingular); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
55 |
|
$table->{twillIncrementsMethod()}('id'); |
|
77
|
55 |
|
$table->{twillIntegerMethod()}("{$tableNameSingular}_id")->unsigned(); |
|
78
|
|
|
|
|
79
|
55 |
|
$table->softDeletes(); |
|
80
|
55 |
|
$table->timestamps(); |
|
81
|
55 |
|
$table->string('locale', 7)->index(); |
|
82
|
55 |
|
$table->boolean('active'); |
|
83
|
|
|
|
|
84
|
55 |
|
$table->foreign("{$tableNameSingular}_id", "fk_{$tableNameSingular}_translations_{$tableNameSingular}_id")->references('id')->on($tableNamePlural)->onDelete('CASCADE'); |
|
85
|
55 |
|
$table->unique(["{$tableNameSingular}_id", 'locale'], "{$tableNameSingular}_id_locale_unique"); |
|
86
|
55 |
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
if (!function_exists('createDefaultSlugsTableFields')) { |
|
90
|
|
|
/** |
|
91
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $table |
|
92
|
|
|
* @param string $tableNameSingular |
|
93
|
|
|
* @param string|null $tableNamePlural |
|
94
|
|
|
* @return void |
|
95
|
|
|
*/ |
|
96
|
|
|
function createDefaultSlugsTableFields($table, $tableNameSingular, $tableNamePlural = null) |
|
97
|
|
|
{ |
|
98
|
28 |
|
if (!$tableNamePlural) { |
|
99
|
28 |
|
$tableNamePlural = Str::plural($tableNameSingular); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
28 |
|
$table->{twillIncrementsMethod()}('id'); |
|
103
|
28 |
|
$table->{twillIntegerMethod()}("{$tableNameSingular}_id")->unsigned(); |
|
104
|
|
|
|
|
105
|
28 |
|
$table->softDeletes(); |
|
106
|
28 |
|
$table->timestamps(); |
|
107
|
28 |
|
$table->string('slug'); |
|
108
|
28 |
|
$table->string('locale', 7)->index(); |
|
109
|
28 |
|
$table->boolean('active'); |
|
110
|
28 |
|
$table->foreign("{$tableNameSingular}_id", "fk_{$tableNameSingular}_slugs_{$tableNameSingular}_id")->references('id')->on($tableNamePlural)->onDelete('CASCADE')->onUpdate('NO ACTION'); |
|
111
|
28 |
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
if (!function_exists('createDefaultRelationshipTableFields')) { |
|
115
|
|
|
/** |
|
116
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $table |
|
117
|
|
|
* @param string $table1NameSingular |
|
118
|
|
|
* @param string $table2NameSingular |
|
119
|
|
|
* @param string|null $table1NamePlural |
|
120
|
|
|
* @param string|null $table2NamePlural |
|
121
|
|
|
* @return void |
|
122
|
|
|
*/ |
|
123
|
|
|
function createDefaultRelationshipTableFields($table, $table1NameSingular, $table2NameSingular, $table1NamePlural = null, $table2NamePlural = null) |
|
124
|
|
|
{ |
|
125
|
|
|
if (!$table1NamePlural) { |
|
126
|
|
|
$table1NamePlural = Str::plural($table1NameSingular); |
|
127
|
|
|
} |
|
128
|
|
|
if (!$table2NamePlural) { |
|
129
|
|
|
$table2NamePlural = Str::plural($table2NameSingular); |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
$table->{twillIntegerMethod()}("{$table1NameSingular}_id")->unsigned(); |
|
133
|
|
|
$table->{twillIntegerMethod()}("{$table2NameSingular}_id")->unsigned(); |
|
134
|
|
|
|
|
135
|
|
|
$table->foreign("{$table1NameSingular}_id")->references('id')->on($table1NamePlural)->onDelete('cascade'); |
|
136
|
|
|
$table->foreign("{$table2NameSingular}_id")->references('id')->on($table2NamePlural)->onDelete('cascade'); |
|
137
|
|
|
$table->index(["{$table2NameSingular}_id", "{$table1NameSingular}_id"], "idx_{$table1NameSingular}_{$table2NameSingular}_" . Str::random(5)); |
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
if (!function_exists('createDefaultRevisionsTableFields')) { |
|
142
|
|
|
/** |
|
143
|
|
|
* @param \Illuminate\Database\Schema\Blueprint $table |
|
144
|
|
|
* @param string $tableNameSingular |
|
145
|
|
|
* @param string|null $tableNamePlural |
|
146
|
|
|
* @return void |
|
147
|
|
|
*/ |
|
148
|
|
|
function createDefaultRevisionsTableFields($table, $tableNameSingular, $tableNamePlural = null) |
|
149
|
|
|
{ |
|
150
|
28 |
|
if (!$tableNamePlural) { |
|
151
|
28 |
|
$tableNamePlural = Str::plural($tableNameSingular); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
28 |
|
$table->{twillIncrementsMethod()}('id'); |
|
155
|
28 |
|
$table->{twillIntegerMethod()}("{$tableNameSingular}_id")->unsigned(); |
|
156
|
28 |
|
$table->{twillIntegerMethod()}('user_id')->unsigned()->nullable(); |
|
157
|
|
|
|
|
158
|
28 |
|
$table->timestamps(); |
|
159
|
28 |
|
$table->json('payload'); |
|
160
|
28 |
|
$table->foreign("{$tableNameSingular}_id")->references('id')->on("{$tableNamePlural}")->onDelete('cascade'); |
|
161
|
28 |
|
$table->foreign('user_id')->references('id')->on(config('twill.users_table', 'twill_users'))->onDelete('set null'); |
|
162
|
28 |
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|