回答編集履歴
3
if文を修正しました
answer
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
```php
|
4
4
|
$post = Post::findOrFail($id);
|
5
5
|
$post->fill($request->all());
|
6
|
-
if ($request->file('image')->isValid()) {
|
6
|
+
if ($request->hasFile('image') && $request->file('image')->isValid()) {
|
7
7
|
$imagepath = $request->image->store('public');
|
8
8
|
$post->image = $imagepath; // 新しいパスをセット
|
9
9
|
}
|
2
if文のコメントを削除
answer
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
```php
|
4
4
|
$post = Post::findOrFail($id);
|
5
5
|
$post->fill($request->all());
|
6
|
-
if ($request->file('image')->isValid()) {
|
6
|
+
if ($request->file('image')->isValid()) {
|
7
7
|
$imagepath = $request->image->store('public');
|
8
8
|
$post->image = $imagepath; // 新しいパスをセット
|
9
9
|
}
|
1
コードの1行目を追加
answer
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
こういうことでしょうか?
|
2
2
|
|
3
3
|
```php
|
4
|
+
$post = Post::findOrFail($id);
|
4
5
|
$post->fill($request->all());
|
5
6
|
if ($request->file('image')->isValid()) { // ファイルが存在してアップロードに成功した場合
|
6
7
|
$imagepath = $request->image->store('public');
|