URLで直接アクセスしたときに画像は表示されますか?
http://localhost/storage/image/画像のパス
Like!
laravelにてpublic/storage
に保存されている画像パスを持ってきて画像を表示させたいです。
storageに画像パスが保存されていることは確認できています。
viewを検証ツールで確認しても特にエラーは起きていないようです。
<img src="{{ asset('storage/image/' . $recipe->image_path )}}" alt="">
画像を保存する処理(contoroller)
if (isset($form['image'])) {//変数に値が入っているかをチェック
$path = $request->file('image')->store('public/image');// 画像をstorage/app/public/image配下に保存
$recipe->image_path = basename($path);//パスからを取得したファイル名をimage_pathカラムに保存
} else {
$recipe->image_path = null;
}
シンボリックリンクをしましたが表示させることができませんでした
php artisan storage:link
http://127.0.0.1:8000/storage/image/画像ファイル名
の実行結果
Status Code: 200 OK
を返している
@foreach($posts as $recipe)
<tr>
<th scope="row">{{ $recipe->recipe_name }}</th>
<td>{{ \Str::limit($recipe->comment, 200 )}}</td>
<td>
<img src="{{ asset('storage/image/' . $recipe->image_path) }}" alt="">
</td>
</tr>
@endforeach
画像ファイル拡張子(heic)
URLで直接アクセスしたときに画像は表示されますか?
http://localhost/storage/image/画像のパス
@yuktkhs
Questioner@yuktkhs
Questioner@yuktkhs
Questioner保存する処理のstoreバスを変更してみてください。
store('public/image') => store('image')
@yuktkhs
Questioner@yuktkhs
Questioner