Laravel:存储不将文件放在公用文件夹中 [英] Laravel: Storage not putting file inside public folder
本文介绍了Laravel:存储不将文件放在公用文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我使用时:
Storage::putFile('documents', $content, 'public');
我希望公用目录内的文件夹结构如下:
I expect the folder structure inside public directory, like:
+
+-- storage
+--|-- app
+--|--|-- public
+--|--|--|-- documents
+--|--|--|--|-- XyZ.pdf
+
代替:
+
+-- storage
+--|-- app
+--|--|-- documents
+--|--|--|-- XyZ.pdf
+--|--|-- public
+
因此,要强制存储在正确的"位置,我需要明确放置:
So, to force storage at "right" place I need to explicit put:
Storage::putFile('public/documents', $content, 'public');
什么返回给我一个我无法保存在数据库的路径,因为它的值是"public/documents/xyz.pdf"
,并且不能与 asset()一起正常使用
助手.
What returns me a path that I'm not able to save at database because its values is "public/documents/xyz.pdf"
and will not work properly with asset()
helper.
如何使用 Storage
门面将文件放入 storage/app/public
内?
How to use Storage
facade to put files inside storage/app/public
?
推荐答案
文档中没有明确说明.
查看 config/filesystems.php
,我们有一个 public
磁盘.只需使用它即可:
Looking at config/filesystems.php
, we have a public
disk. Just use it:
Storage::disk('public')->put('documents', $content);
这篇关于Laravel:存储不将文件放在公用文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文