質問編集履歴

2

migrate 表示

2020/09/10 03:13

投稿

m.kk
m.kk

スコア23

test CHANGED
File without changes
test CHANGED
@@ -57,3 +57,129 @@
57
57
 
58
58
 
59
59
  よろしくお願いします。
60
+
61
+
62
+
63
+ ```
64
+
65
+ animal table
66
+
67
+ <?php
68
+
69
+
70
+
71
+
72
+
73
+ class CreateAnimalsTable extends Migration
74
+
75
+ {
76
+
77
+
78
+
79
+ public function up()
80
+
81
+ {
82
+
83
+ Schema::create('animals', function (Blueprint $table) {
84
+
85
+ $table->increments('id');
86
+
87
+ $table->string('animal_image')->comment('画像');
88
+
89
+ $table->string('name');
90
+
91
+ $table->string('kinds');
92
+
93
+ $table->timestamps();
94
+
95
+
96
+
97
+ });
98
+
99
+ }
100
+
101
+
102
+
103
+ public function down()
104
+
105
+ {
106
+
107
+ Schema::dropIfExists('animals');
108
+
109
+ }
110
+
111
+ }
112
+
113
+ ```
114
+
115
+
116
+
117
+ ```
118
+
119
+
120
+
121
+ cats table
122
+
123
+
124
+
125
+ <?php
126
+
127
+
128
+
129
+ class CreateCatsTable extends Migration
130
+
131
+ {
132
+
133
+
134
+
135
+ public function up()
136
+
137
+ {
138
+
139
+ Schema::create('cats', function (Blueprint $table) {
140
+
141
+ $table->increments('id');
142
+
143
+ $table->unsignedInteger('user_id')->unsigned()->comment('ユーザーID');
144
+
145
+ $table->unsignedInteger('animal_id');
146
+
147
+
148
+
149
+ $table->string('cats_image')->comment('画像');
150
+
151
+ $table->string('cats_name');
152
+
153
+ $table->timestamps();
154
+
155
+
156
+
157
+ $table->index('id');
158
+
159
+ $table->index('user_id');
160
+
161
+ $table->index('animal_id');
162
+
163
+
164
+
165
+ $table->foreign('user_id')->references('id')->on('users')->onDelete('set null')->onUpdate('cascade');
166
+
167
+ $table->foreign('animal_id')->references('id')->on('animals');
168
+
169
+ });
170
+
171
+ }
172
+
173
+
174
+
175
+ public function down()
176
+
177
+ {
178
+
179
+ Schema::dropIfExists('cats');
180
+
181
+ }
182
+
183
+ }
184
+
185
+ ```

1

cats

2020/09/10 03:13

投稿

m.kk
m.kk

スコア23

test CHANGED
File without changes
test CHANGED
@@ -34,7 +34,7 @@
34
34
 
35
35
  ->select('animals.*', 'cats.updated_at')
36
36
 
37
- ->orderBy('sentences.updated_at', 'DESC')->get();
37
+ ->orderBy('cats.updated_at', 'DESC')->get();
38
38
 
39
39
  }
40
40