在 laravel 中以 balde 视图从数据库中获取图像

Fetch images from database in balde view in laravel

我将图像保存在我的数据库中(图像的名称),图像保存在我的 public/images 目录中(有效)。我有一个太多的关系,我放了一个 dd() 来查看我是否从数据库中正确地获取了数据,是的,它是正确的。现在我想在我的视图中看到这些图像,但我不知道如何为此编写正确的路径。我尝试这样的事情:

@foreach($result as $res)

@foreach($res->images as $file)//in images i have the pics
<tr>
 <td><img src="{{ asset('public/images/' . $file->file_name)}}" /></td>

</tr>
@endforeach
@endforeach``

$file->file_name 在 Visual studio 代码中未被视为变量。我怎样才能获得正确的路径来正确显示我的照片?谢谢

asset() 函数中删除 public,此助手指向 public 目录

<td><img src="{{ asset('images/' . $file->file_name)}}" /></td>

ref link https://laravel.com/docs/8.x/helpers#method-asset