質問編集履歴

2

変更

2022/09/08 20:32

投稿

JuniorSirius
JuniorSirius

スコア38

test CHANGED
File without changes
test CHANGED
@@ -113,4 +113,76 @@
113
113
  }
114
114
 
115
115
  ```
116
+ ### 追記コード
117
+ `database/migrations/***_create_images_table.php`
118
+ ```php
119
+ <?php
116
120
 
121
+ use Illuminate\Database\Migrations\Migration;
122
+ use Illuminate\Database\Schema\Blueprint;
123
+ use Illuminate\Support\Facades\Schema;
124
+
125
+ return new class extends Migration
126
+ {
127
+ /**
128
+ * Run the migrations.
129
+ *
130
+ * @return void
131
+ */
132
+ public function up()
133
+ {
134
+ Schema::create('images', function (Blueprint $table) {
135
+ $table->id();
136
+ $table->string('name');
137
+ $table->timestamps();
138
+ });
139
+ }
140
+
141
+ /**
142
+ * Reverse the migrations.
143
+ *
144
+ * @return void
145
+ */
146
+ public function down()
147
+ {
148
+ Schema::dropIfExists('images');
149
+ }
150
+ };
151
+
152
+ ```
153
+ `database/migrations/***_create_tweet_images_table.php`
154
+ ```php
155
+ <?php
156
+
157
+ use Illuminate\Database\Migrations\Migration;
158
+ use Illuminate\Database\Schema\Blueprint;
159
+ use Illuminate\Support\Facades\Schema;
160
+
161
+ return new class extends Migration
162
+ {
163
+ /**
164
+ * Run the migrations.
165
+ *
166
+ * @return void
167
+ */
168
+ public function up()
169
+ {
170
+ Schema::create('tweet_images', function (Blueprint $table) {
171
+ $table->foreignId('tweet_id')->constrained('tweets')->cascadeOnDelete();
172
+ $table->foreignId('image_id')->constrained('images')->cascadeOnDelete();
173
+ $table->timestamps();
174
+ });
175
+ }
176
+
177
+ /**
178
+ * Reverse the migrations.
179
+ *
180
+ * @return void
181
+ */
182
+ public function down()
183
+ {
184
+ Schema::dropIfExists('tweet_images');
185
+ }
186
+ };
187
+
188
+ ```

1

改善

2022/09/07 21:03

投稿

JuniorSirius
JuniorSirius

スコア38

test CHANGED
File without changes
test CHANGED
@@ -3,9 +3,10 @@
3
3
  `ImageFactory`で`faker`を通じて、imageメソッドによる該当のディレクトリに画像を出力されるように構成してから、`TweetsSeeder`から4件の画像を紐づけるようにシーディングを行いました。
4
4
 
5
5
  しかし、`images`テーブルの`name`カラムにおいて`faker`によるデータを保存し、そこにfakerによる画像が反映され、`・・・b3.png`などとなるはずですが、どの値も`0`になってしまします。
6
- 教科書通りにソースコードも全てコピーで再度反映させたはずですが、何がいけないのでしょうか?
7
6
 
7
+ ちなみに`storage/app/public/images`に出力されるはずでそこには何にも反映されませんでした。
8
+
8
- ご教授いたただけたらお願いいたします。
9
+ 教科書通りにソースコードも全てコピーで再度反映させたはずですが、何がいけないのでしょうか?ご教授いたただけたらお願いいたします。
9
10
 
10
11
  バージョンは`require a PHP version ">= 8.1.0". You are running 8.0.19`でした。
11
12