我能';在laravel中找不到存储Facade的实现
我刚加入laravel,现在在laravel的文件系统中工作 (我想做一些常见的filesttem过程,比如-make dir-copy-put-delete-ect) 我用的是laravel的“存储”立面 但是当我打字的时候 我在代码中这样引用了上面的类我能';在laravel中找不到存储Facade的实现,laravel,filesystems,storage,Laravel,Filesystems,Storage,我刚加入laravel,现在在laravel的文件系统中工作 (我想做一些常见的filesttem过程,比如-make dir-copy-put-delete-ect) 我用的是laravel的“存储”立面 但是当我打字的时候 我在代码中这样引用了上面的类 use Illuminate\Support\Facades\Storage; 例如: if (file_exists(public_path($oldImage))) { Storage::delete
use Illuminate\Support\Facades\Storage;
例如:
if (file_exists(public_path($oldImage))) {
Storage::delete($oldImage);
}
什么都没有发生,当我参考类代码时,我发现:
namespace Illuminate\Support\Facades;
/**
* @see \Illuminate\Filesystem\FilesystemManager
*/
class Storage extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'filesystem';
}
}
那么,实施在哪里?如果您有其他方法来处理
文件系统进程而不是“存储”外观 存储是一个
facade
并访问位于此处的类Filesystem
:vendor/laravel/framework/src/light/Filesystem/Filesystem.php
正如您在中所看到的,代码片段使用存储
更新:
您应该添加
使用存储
能够使用存储
门面。存储是门面
并访问位于此处的类文件系统
:vendor/laravel/framework/src/light/Filesystem/Filesystem.php
正如您在中所看到的,代码片段使用存储
更新:
您应该添加
使用存储
可以使用存储
门面。公共路径函数将完全限定路径返回到laravel应用程序内的公共目录即公共目录。使用存储时,路径设置为Storage/app目录
if (file_exists(public_path($oldImage))) {
//public_path($oldImage) will check for file in public directory
Storage::delete($oldImage); //Will delete file in storage/app directory
}
修改后的代码应该是
if(Storage::has($oldImage)){
Storage::delete($oldImage);
}
public_path函数将完全限定的路径返回到laravel应用程序中的公共目录ie public directory。使用存储时,路径设置为Storage/app目录
if (file_exists(public_path($oldImage))) {
//public_path($oldImage) will check for file in public directory
Storage::delete($oldImage); //Will delete file in storage/app directory
}
修改后的代码应该是
if(Storage::has($oldImage)){
Storage::delete($oldImage);
}
我建议阅读Laravel 8.X文档以获得初步了解: 注意:在你过于激动之前,确保你理解
本地
和公共
之间的区别
对于初学者,您应该将第一个目标定为上载文件并获取UploadedFile
类型
您可以通过$request->file('name')
等方式访问单个文件,或通过以下方式访问图像数组:
// $request->input('images')
foreach ($images as $image) {
\Log::debug($image->getClientOriginalName());
}
如果您的文件上载可以是单个和/或多个,我建议使用数组方法,因为数组中的单个文件允许您对单个和多个上载使用相同的语法(即:foreach循环可以处理一个图像,无需额外代码)
下面是一个例子:
use Illuminate\Support\Facades\Storage;
$slug = 'davids-sandwich-photos';
foreach ($images as $image) {
Storage::putFileAs(
'images' .'/'. $slug,
$image,
$image->getClientOriginalName()
);
}
Storage::putFileAs()
可以接受3个参数:目录、内容、文件名。您可以在上面的代码中看到,我插入了静态目录名和派生目录名的混合。您可以执行类似于“图像”的操作$鼻涕虫。Auth::user()->id
将文件保存在/images/davids sandwich photos/11
中
然后,检查您的回购目录:/storage/app/
,并查找图像
目录
if (file_exists(public_path($oldImage))) {
//public_path($oldImage) will check for file in public directory
Storage::delete($oldImage); //Will delete file in storage/app directory
}
您可以在测试时手动删除文件夹,以使您的方向正确
这应该足以让大多数人开始
要避免使用存储
外观,您可以使用:
foreach ($images as $image) {
$image->storeAs(
'examples' .'/'. $slug,
$image->getClientOriginalName(),
'public'
);
}
--
如果您想开始操作驱动程序,请查看磁盘部分下的config/filesystems.php
,但我不是数据库管理专家
我在旅途中也保存了这个:。如果你被符号链接之类的东西卡住了,你可能需要它
<img
v-for="image in example.images"
:key="image.filename"
:src="`/storage/examples/${example.slug}/${image.filename}`"
>
注意:如果您的文件位于存储库中,Vue JS的重要部分是使用
,文件名为/storage/app/public/examples/slug/filename.jpg
,请密切注意每个字符。我建议阅读Laravel 8.X文档以获得初步信息:
注意:在你过于激动之前,确保你理解本地
和公共
之间的区别
对于初学者,您应该将第一个目标定为上载文件并获取UploadedFile
类型
您可以通过$request->file('name')
等方式访问单个文件,或通过以下方式访问图像数组:
// $request->input('images')
foreach ($images as $image) {
\Log::debug($image->getClientOriginalName());
}
如果您的文件上载可以是单个和/或多个,我建议使用数组方法,因为数组中的单个文件允许您对单个和多个上载使用相同的语法(即:foreach循环可以处理一个图像,无需额外代码)
下面是一个例子:
use Illuminate\Support\Facades\Storage;
$slug = 'davids-sandwich-photos';
foreach ($images as $image) {
Storage::putFileAs(
'images' .'/'. $slug,
$image,
$image->getClientOriginalName()
);
}
Storage::putFileAs()
可以接受3个参数:目录、内容、文件名。您可以在上面的代码中看到,我插入了静态目录名和派生目录名的混合。您可以执行类似于“图像”的操作$鼻涕虫。Auth::user()->id
将文件保存在/images/davids sandwich photos/11
中
然后,检查您的回购目录:/storage/app/
,并查找图像
目录
if (file_exists(public_path($oldImage))) {
//public_path($oldImage) will check for file in public directory
Storage::delete($oldImage); //Will delete file in storage/app directory
}
您可以在测试时手动删除文件夹,以使您的方向正确
这应该足以让大多数人开始
要避免使用存储
外观,您可以使用:
foreach ($images as $image) {
$image->storeAs(
'examples' .'/'. $slug,
$image->getClientOriginalName(),
'public'
);
}
--
如果您想开始操作驱动程序,请查看磁盘部分下的config/filesystems.php
,但我不是数据库管理专家
我在旅途中也保存了这个:。如果你被符号链接之类的东西卡住了,你可能需要它
<img
v-for="image in example.images"
:key="image.filename"
:src="`/storage/examples/${example.slug}/${image.filename}`"
>
注意:Vue JS的重要部分是使用
,如果您的文件位于存储库中,则文件名为/storage/app/public/examples/slug/filename.jpg
。请密切注意每个字符。我在构造函数中使用了“Filesystem”,它可以正常工作,但请回到我最初的问题“存储”是什么facade类在我的例子中不起作用,,,为什么它不指向“文件系统”