适配路径支持设置为空

This commit is contained in:
Wisp X
2022-04-01 16:20:23 +08:00
parent dec4e6fdb7
commit 798e72f634
2 changed files with 3 additions and 3 deletions
+2 -1
View File
@@ -164,7 +164,8 @@ class Image extends Model
public function pathname(): Attribute
{
return new Attribute(fn() => "{$this->path}/{$this->name}");
$path = $this->path ? "{$this->path}/" : '';
return new Attribute(fn() => "{$path}{$this->name}");
}
public function url(): Attribute
+1 -2
View File
@@ -160,7 +160,7 @@ class ImageService
$image->fill([
'md5' => md5_file($file->getRealPath()),
'sha1' => sha1_file($file->getRealPath()),
'path' => dirname($pathname),
'path' => $configs->get(GroupConfigKey::PathNamingRule) ? dirname($pathname) : '',
'name' => basename($pathname),
'origin_name' => $file->getClientOriginalName(),
'size' => $file->getSize() / 1024,
@@ -541,7 +541,6 @@ class ImageService
} catch (\Throwable $e) {
Utils::e($e, '生成缩略图时出现异常');
// TODO 直接将原图存下来?
}
}
}