実現したいこと
- Laravelでの画像表示
前提
超初心者です。勉強中で現在画像投稿アプリを作成しております。
Cloudinaryで保存した画像をViewに表示させたいと考えています。
Cloudinaryには画像を保存できているのですが、LaravelでのViewの方で画像を表示できない状態です。
PHPでのLaravelを使用
発生している問題
こちらの画像のように画像の代わりにアイコンが表示されてしまいます。
調べても解決策が見つかりません。
原因はControllerでCloudinaryから画像を取得できていないのではないかと考えています。
原因を教えていただきたいです。よろしくお願いいたします。
index.blade.php
<form action="/posts/{{ $post->id }}" method="post" enctype="multipart/form-data"> @csrf @method('PUT') <div class="image"> <input type="file" name="image"> <input type="submit" name="ima" value="登録"> </div> </form> <div> <img src="{{ $post->image_url }}" alt="画像が読み込めません。"/> </div>
PostController.php
class PostController extends Controller { public function index(Post $post) { return view('posts.index')->with(['posts' => $post->getPaginateByLimit(1)]); dd($image_url); } public function update(PostRequest $request, Post $post) { $input_post = $request['post']; $post->fill($input_post)->save(); $image_url = Cloudinary::upload($request->file('image')->getRealPath())->getSecurePath(); $input_post += ['image_url' => $image_url]; return redirect('/posts/' . $post->id); } public function create(Category $category) { return view('posts.create')->with(['categories' => $category->get()]); } public function store(PostRequest $request, Post $post) { $input = $request['post']; $post->fill($input)->save(); return redirect('/posts/' . $post->id); }

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。