作者:camera98 | 来源:互联网 | 2023-02-04 10:43
我Storage::delete($filepath);
在Laravel 5.4中无法正常工作。
我已经搜索了与此问题有关的其他人,但是大多数其他人似乎都犯了错误,该错误提供的文件路径中没有上述内容/
,但这不是我的问题。
我正在使用use Illuminate\Support\Facades\Storage;
(根据Laravel文档),并且我注意到PHPStorm说中出现错误Method delete not found in Illuminate\Support\Facades\Storage
。
我的代码看起来像;
get()->first();
Storage::delete($image->filepath);
return Files::destroy($id);
} catch ( \Exception $e) {
return back()->with('alert-warning', 'Something went wrong: ' . $e);
}
}
我的$ image-> filepath看起来像 /Users/usrname/sites/sitename/storage/app/images/34/o8Aq1T3Hi67sOtuTgBh9P7QWA1Ahj4KH2QBR77n0.png
有人能帮忙吗?
1> Ash..:
好的,因此事实证明$ filepath必须相对于应用程序的存储根目录,而不是文件的完整文件路径!
我使用一个函数将文件路径更新为;
images/34/o8Aq1T3Hi67sOtuTgBh9P7QWA1Ahj4KH2QBR77n0.png
它的魅力。