在 laravel 7 中显示图像

Display image in laravel 7

我用

存储图像
$cat->picture = $request->file('catpicture')->store('public/catpictures');
$cat->save();

我在“/var/www/html/project/storage/app/public/catpictures”中执行了一个ls,图像被保存了

我创建了符号链接

php artisan storage:link
The [/var/www/html/project/public/storage] link has been connected to [/var/www/html/project/storage/app/public].
The links have been created.

在我的 blade 我有:

<img src="{{url($cat->picture)}}" class="img-thumbnail" alt="Responsive image">

即"public/catpictures/IgTx81OYKVymthuzTydFVepGvFZGALeeW1FmHpas.png"

图像不显示,我错过了什么? 来源是 http://127.0.0.1:8000/public/catpictures/IgTx81OYKVymthuzTydFVepGvFZGALeeW1FmHpas.png

而不是使用 url,最好使用 asset 来检索资产

实际上您不需要在 store() 函数中添加 public 前缀。当您调用 store() 时,它将使用来自 config/filesystems.php 的路径。该路径将从 default disks.

Asset vs Url

<img src="{{asset('/storage/' . $cat->picture)}}" class="img-thumbnail" alt="Responsive image">