修改文件目录
vendor/dcat/laravel admin/src/Form/field/UploadField接口名称 deleteFile
优化代码
public function deleteFile($paths)
{
foreach ((array)$paths as $path) {
if (Str::startsWith($path, ['http://', 'https://'])) {
return str_replace(asset('/upload/'), '', $path);
}
}
if (!$paths || $this->retainable) {
return;
}
if (method_exists($this, 'destroyThumbnail')) {
$this->destroyThumbnail($paths);
}
$storage = $this->getStorage();
foreach ((array)$paths as $path) {
if ($storage->exists($path)) {
$storage->delete($path);
} else {
$prefix = $storage->url('');
$path = str_replace($prefix, '', $path);
if ($storage->exists($path)) {
$storage->delete($path);
}
}
}
}
其他方法
$form->submitted(function (Form $form) {
// 获取表单模型
$model = $form->model();
// 手动调用属性访问器,修改数据值
$processedImage = $model->getProductImageAttribute($model->product_image);
// dd($processedImage);
// 更新模型的产品图片字段
$model->product_image = ltrim($processedImage, '/');
$model->save();
});