Laravel 8 图片未显示

Laravel 8 image not showing

我正在使用 Laravel 8

正在尝试显示来自 storage/app/subject_image/ 路径的图像,但未显示。

下面是我在 blade

上的代码
<img src="{{asset("storage/subject_image/$data->subject_image")}}" alt="">

我还检查了 chrome 上的元素,它显示正确的路径和正确的图像名称仍然没有显示。下面是 inpsect 元素截图

重要提示

storage folder is not publicly accessible from the web browser and because of that we will have to create a symbolic link

什么是符号 link ?

you can say symbolic link as alias or pointer to your path directory

在哪里可以配置符号 links?

You may configure symbolic links in your filesystems configuration file that is located at path config/filesystems.php

现在让我们配置符号 link

假设我们有一个图像文件位于 storage/app/folder1/img.jpg

现在让我们为上述路径配置符号 link -

步骤 1:打开 config/filesystems.php 并配置自定义符号 link

public_path('my_custom_symlink_1') => storage_path('app/folder1'),

第 2 步:现在 运行 Artisan command

php artisan storage:link

仅在文件系统中配置符号 link 是行不通的,您必须 运行 php artisan storage:link 到 create/active 符号 link.

步骤 3:现在您可以使用符号 link

在浏览器中访问您的目标文件

<img src="{{asset("my_custom_symlink_1/img.jpg")}}" >