我正在尝试显示存储/应用/公共文件夹中的图像 . 每当我的控制器从这个文件夹中检索图像时
$images = Storage::files('public');
从此处检索的文件以 public/
为前缀,而不是 storage/
. 这导致的问题是可以找到图像 localhost/storage/filename.jpg
,但无法找到 localhost/public/filename.jpg
或 localhost/storage/public/filename.jpg
. 我可以通过手动切断公共前缀并将其替换为存储来解决此问题,但这不是一种特别优雅的做事方式 .
我已经运行命令php artisan storage:link并重新运行它会产生 The "public/storage" directory already exists.
消息 .
1 回答
Laravel在存储配置中附带了一个内置的
public
磁盘 .要列出
storage/app/public
文件夹 without 前缀中的所有文件,请使用:要在
storage/app/public
文件夹中获取正确的文件URL,请使用:要返回
storage/app/public
文件夹中文件的URL数组,以下是一个示例组合: