当方、初心者でlaravelも初めて扱っております。
今現在、画像実装機能を実装しているのですがうまく反映されず、デフォルトのアイコン?的なのが、出現している状態です。
投稿した画像自体はdbにも保存されていて、ライブラリのstorage/app/public/imageに保存されています。
また、php artisan storage:linkのコマンドで、public/storageにlinkが繋がっていると思います。
consoleログにはFailed to load resource: the server responded with a status of 404 (Not Found)と出ているので画像を特定できていないのかなと思っています。ただ、自分ではもうどうしたらいいか、分からなくなってきたのでお力を貸していただけたらと思います。よろしくお願いいたします。
開発環境
mysql: ver 5.6.42,
laravel: ver 5.8.17
php: ver 7.2.18
画像が表示される箇所のコード <h5 class="card-title"> 投稿者:{{ $post->user->name }}</h5> <h5 class="card-title">{{ $post->title }}</h5> <p class="card-text">{{ $post->contenbt }}</p> <img src="{{ asset('storage/image'.$post->image) }}"> </div> </div>
画像を保存する処理を書いたコード public function store(PostRequest $request) { if($request->file('image')) { $post = new Post; // $input = $request->only($post->getFillable()); $post->user_id = $request->user_id; $post->category_id = $request->category_id; $post->content = $request->content; $post->title = $request->title; $filename = $request->file('image')->store('public/image'); $post->image = basename($filename); // if(!isset($input['image'])) { // array_set($input, 'image', basename($filename)); // } $post = $post->save(); } // $post = $post->save(); return redirect('/');
回答2件
あなたの回答
tips
プレビュー