forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2017_03_11_215455_ChangeServiceVariablesValidationRules.php
More file actions
47 lines (41 loc) · 1.39 KB
/
2017_03_11_215455_ChangeServiceVariablesValidationRules.php
File metadata and controls
47 lines (41 loc) · 1.39 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
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ChangeServiceVariablesValidationRules extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
Schema::table('service_variables', function (Blueprint $table) {
$table->renameColumn('regex', 'rules');
});
DB::transaction(function () {
foreach (DB::table('service_variables')->get() as $variable) {
$variable->rules = ($variable->required) ? 'required|regex:' . $variable->rules : 'regex:' . $variable->rules;
$variable->save();
}
});
Schema::table('service_variables', function (Blueprint $table) {
$table->dropColumn('required');
});
}
/**
* Reverse the migrations.
*/
public function down()
{
Schema::table('service_variables', function (Blueprint $table) {
$table->renameColumn('rules', 'regex');
$table->boolean('required')->default(true)->before('regex');
});
DB::transaction(function () {
foreach (DB::table('service_variables')->get() as $variable) {
$variable->regex = str_replace(['required|regex:', 'regex:'], '', $variable->regex);
$variable->save();
}
});
}
}