【发布时间】:2021-11-11 17:58:12
【问题描述】:
当我使用 php unlink 方法时,我可以使用以下逻辑从本地驱动程序中删除图像,但是当我使用 Storage 门面时,帖子被删除但图像没有被删除。我尝试过使用 Facade 方式,但似乎无法正常工作。我错过了什么?
public function destroy(Post $post)
{
// unlink('storage/'.$post->imagePath);
Storage::delete('storage/'.$post->imagePath);
$post->delete();
return redirect(route('posts.index'))->with('flash', 'Post Deleted Successfully');
}
【问题讨论】:
-
不要在删除方法中传递
storage/。存储门面 ID 自动使用storage目录中的文件。 -
我在通过 storage/ 之前尝试了
Storage::delete($post->imagePath);,但效果不佳。