Laravel Nova - 如何在删除相应的数据库条目时从磁盘中删除图像?

Laravel Nova - How to remove image from disk when corresponding database entry is removed?

我是 Laravel 和 Nova 的新手,想构建一个 Resource 来存储 image 以及其他一些数据。上传后,image file 存储在 disk (storage/app/public) 而所有其他数据(包括 image link)存储在数据库中。

stored image:

database:

当我删除 Nova 中的这个数据库条目时,stored image 不受它的影响。这不会溢出我在生产中的存储吗? Nova 是否提供了 clear unused images from disk 的方法,还是我必须使用 Laravel 手动删除它?无论哪种情况,我都将不胜感激。

这是我的Resource:

fields函数
public function fields(Request $request)
{
    return [
        ID::make(__('ID'), 'id')->sortable(),
        Text::make('Heading'),
        Text::make('Content'),
        File::make('Image')->disk('public'),
    ];
}

Nova doc 通过将 prunable 添加到 Image function(或任何其他 File function)来为此提供了一个简单的解决方案:

Image::make('Profile Photo')->disk('public')->prunable()

当图像被删除或更新时,这种方式会从存储中删除图像。