|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+<?php
|
|
|
2
|
+
|
|
|
3
|
+use Illuminate\Database\Migrations\Migration;
|
|
|
4
|
+use Illuminate\Database\Schema\Blueprint;
|
|
|
5
|
+use Illuminate\Support\Facades\DB;
|
|
|
6
|
+use Illuminate\Support\Facades\Schema;
|
|
|
7
|
+
|
|
|
8
|
+return new class extends Migration
|
|
|
9
|
+{
|
|
|
10
|
+ /**
|
|
|
11
|
+ * Run the migrations.
|
|
|
12
|
+ */
|
|
|
13
|
+ public function up(): void
|
|
|
14
|
+ {
|
|
|
15
|
+ Schema::table('projects', function (Blueprint $table) {
|
|
|
16
|
+ $table->json('contact')->nullable()->after('design_unit');
|
|
|
17
|
+ });
|
|
|
18
|
+
|
|
|
19
|
+ $projects = DB::table('projects')->get();
|
|
|
20
|
+
|
|
|
21
|
+ foreach ($projects as $project) {
|
|
|
22
|
+ $contactUnit = json_decode($project->contact_unit, true);
|
|
|
23
|
+ $contactPhone = json_decode($project->contact_phone, true);
|
|
|
24
|
+ $inversmentPhone = json_decode($project->inversment_phone, true);
|
|
|
25
|
+
|
|
|
26
|
+ $contact = [];
|
|
|
27
|
+
|
|
|
28
|
+ if (is_array($contactUnit)) {
|
|
|
29
|
+ foreach ($contactUnit as $locale => $value) {
|
|
|
30
|
+ $contact[$locale] = $value;
|
|
|
31
|
+ }
|
|
|
32
|
+ }
|
|
|
33
|
+
|
|
|
34
|
+ if (is_array($contactPhone)) {
|
|
|
35
|
+ foreach ($contactPhone as $locale => $value) {
|
|
|
36
|
+ if (isset($contact[$locale])) {
|
|
|
37
|
+ $contact[$locale] .= ' ' . $value;
|
|
|
38
|
+ } else {
|
|
|
39
|
+ $contact[$locale] = $value;
|
|
|
40
|
+ }
|
|
|
41
|
+ }
|
|
|
42
|
+ }
|
|
|
43
|
+
|
|
|
44
|
+ if (is_array($inversmentPhone)) {
|
|
|
45
|
+ foreach ($inversmentPhone as $locale => $value) {
|
|
|
46
|
+ if (isset($contact[$locale])) {
|
|
|
47
|
+ $contact[$locale] .= ' ' . $value;
|
|
|
48
|
+ } else {
|
|
|
49
|
+ $contact[$locale] = $value;
|
|
|
50
|
+ }
|
|
|
51
|
+ }
|
|
|
52
|
+ }
|
|
|
53
|
+
|
|
|
54
|
+ DB::table('projects')
|
|
|
55
|
+ ->where('id', $project->id)
|
|
|
56
|
+ ->update(['contact' => json_encode($contact)]);
|
|
|
57
|
+ }
|
|
|
58
|
+
|
|
|
59
|
+ Schema::table('projects', function (Blueprint $table) {
|
|
|
60
|
+ $table->dropColumn('contact_unit');
|
|
|
61
|
+ $table->dropColumn('contact_phone');
|
|
|
62
|
+ $table->dropColumn('inversment_phone');
|
|
|
63
|
+ });
|
|
|
64
|
+ }
|
|
|
65
|
+
|
|
|
66
|
+ /**
|
|
|
67
|
+ * Reverse the migrations.
|
|
|
68
|
+ */
|
|
|
69
|
+ public function down(): void
|
|
|
70
|
+ {
|
|
|
71
|
+ Schema::table('projects', function (Blueprint $table) {
|
|
|
72
|
+ $table->json('contact_unit')->nullable();
|
|
|
73
|
+ $table->json('contact_phone')->nullable();
|
|
|
74
|
+ $table->json('inversment_phone')->nullable();
|
|
|
75
|
+ $table->dropColumn('contact');
|
|
|
76
|
+ });
|
|
|
77
|
+ }
|
|
|
78
|
+};
|