回答編集履歴

2

誤字修正

2022/04/14 04:40

投稿

Fukusuke0604
Fukusuke0604

スコア554

test CHANGED
@@ -6,6 +6,6 @@
6
6
 
7
7
  ```php
8
8
  //'public/images/'.ファイル名を$delItemに代入
9
- 'public/images/'..$post->image;
9
+ 'public/images/'.$post->image;
10
10
  ```
11
11
  上記に修正して無事にstorage内の画像を削除できました。

1

文法の修正

2022/04/14 04:39

投稿

Fukusuke0604
Fukusuke0604

スコア554

test CHANGED
@@ -1,12 +1,11 @@
1
- ```ここに言語を入力
2
- public function destroy(Post $post)
3
- {
4
- $delImage = Post::find($post->id);
5
- $delFile = $delImage->image;
6
- Storage::delete('public/images/'.$delFile);
7
- $post->delete();
8
- return redirect()->route('home')->with('message', '投稿を削除しました');
9
- }
10
1
  ```
2
+ //'public/images'.ファイル名を$delItemに代入
3
+ $delItem = 'public/images'.$post->image;
4
+ ```
5
+ 上記コードの 'public/images'. に「/」が必要でした。。。
11
6
 
7
+ ```php
12
- $delImage = Post::find($post->id); でPostのIDを取得して、取得したIDからimageを取得する方法でstorageの画像を削除できました!!
8
+ //'public/images/'.ファイル名を$delItemに代入
9
+ 'public/images/'..$post->image;
10
+ ```
11
+ 上記に修正して無事にstorage内の画像を削除できました。