首页 > 解决方案 > 如何修复使用 File 门面保存文件 Laravel 的错误?

问题描述

我收到以下错误:

{"errors":"Method Illuminate\\Filesystem\\Filesystem::create does not exist."}

进口是:

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;

代码是:

$created = File::create(["path" => $path.$filename]);

标签: laravellaravel-5

解决方案


如果你看一下官方的 laravel API,在 File 门面上没有这样的方法 ::create 。

https://laravel.com/api/5.8/Illuminate/Filesystem/Filesystem.html

你想达到什么目的?

如果要创建新文件,请使用 ::put 方法:

int|bool put(string $path, string $contents, bool $lock = false)

查看我提供的 API 链接。或者查看官方文档


推荐阅读