我想检索使用存储的所有文件的公共 url
存储::putFile(‘公共/备件’);
所以,这是我正在使用的问题
存储::文件(“公共/备件”);
但它提供了来自 laravel 存储目录的输出
public/spares/image1.jpg
public/spares/image2.jpg
public/spares/image3.jpg
我怎样才能获得上述的公共链接
http://localhost/laravel/public/storage/spares/image1.jpg
http://localhost/laravel/public/storage/spares/image2.jpg
http://localhost/laravel/public/storage/spares/image3.jpg
**编辑 **
发送文件的最后修改数据以查看
$docs = File::files('storage/document');
$lastmodified = [];
foreach ($docs as $key => $value) {
$docs[$key] = asset($value);
$lastmodified[$key] = File::lastmodified($value);
}
return view('stock.document',compact('docs','lastmodified'));
这个对吗
原文由 Daniel Euchar 发布,翻译遵循 CC BY-SA 4.0 许可协议
Storage::url
怎么样?它甚至适用于本地存储。你可以在这里找到更多: https ://laravel.com/docs/5.4/filesystem#file-urls
如果要从目录中返回所有文件的 url,可以执行以下操作:
如果您正在寻找非门面方式,请不要忘记注入
\Illuminate\Filesystem\FilesystemManager
而不是Storage
门面。编辑:
有两种(或更多)方法可以处理修改日期:
将文件传递给视图。
|您可以将您的
Storage::files($directory)
直接传递给视图,然后在您的模板中使用以下内容:返回一个数组: