首页 > 解决方案 > 无法在 laravel 8 中显示图像

问题描述

我在 Laravel 8 应用程序中有一个搜索功能,可以从数据库中返回数据以及图像。除图像外,其他所有内容均显示。有两个图像列,我需要将这些图像与其他列的数据一起输出。我已经完成了从存储到公共的符号链接,但仍然无法显示图像,但其他列返回数据。我会很感激一些帮助。

图像存储在 storage/public 文件夹中。

存储控制器


public function store(Request $request)
    {

$image1 = uniqid() . $request->file('image1')->getClientOriginalName();

$post = new Post;
$post->name = request('name');
$post->product_image1 = $image1;
$request->file('image1')->storeAs('public', $image1);
$post->save();

return redirect(route('users.index'));

}

搜索控制器

 public function search(Request $request, User $user){
   
        $term = $request->input('search');
        $matchedTerms = Post::where('name', 'LIKE', '%' . $term . '%')->get();

        return view('profiles.search-results', compact('matchedTerms', 'user_id'));

    }

  @forelse($matchedTerms as $matchedTerm)
   <p>{{$matchedTerm->name}}</p>    //this displays okay
  <img src="/storage/public/{{$matchedTerm->product_image1}}" />   //this does not display

  @empty
     <p>no match found</p>
  @endforelse


标签: phplaravel

解决方案


推荐阅读