我使用的是laravel-nova,在一个资源上我使用的是Image字段:
use Laravel\Nova\Fields\Image;
Image::make('Top Image', 'hero_image')
->help('Upload an image to display as hero')
->disk('local')
->maxWidth(400)
->prunable()
->rules('required')
->hideFromIndex(),到目前为止还不错,但因为它是必需的,所以每次我想要编辑资源时,我都必须上传(相同的)图像,这有点烦人,我不想让它不是必需的。
那么,有没有解决这个问题的办法呢?
发布于 2019-07-04 23:06:14
首先,您希望只在创建时才需要它,因此应该使用->creationRules('required')而不是->rules('required')。
但问题是,用户可以删除照片,并保存没有图像的资源。
要解决这个问题,您只需使用->deletable(false)禁用字段上的删除功能。
Image::make('Top Image', 'hero_image')
->help('Upload an image to display as hero')
->disk('local')
->maxWidth(400)
->prunable()
->creationRules('required')
->deletable(false)
->hideFromIndex(),这将允许您更新您的资源,而不必每次都上传图像。并且用户将只能用另一图像替换原始图像。
https://stackoverflow.com/questions/56888917
复制相似问题