From 7a3fa9d6c1dd53bc511977441136819bd797e51c Mon Sep 17 00:00:00 2001 From: 灰大狼 <crazys@126.com> Date: Sun, 3 Mar 2019 16:06:17 +0800 Subject: [PATCH] 修改Attachment模型,防止同名文件重复生成记录。 --- application/common/model/Attachment.php | 9 +++++++++ 1 file changed, 9 insertions(+), 0 deletions(-) diff --git a/application/common/model/Attachment.php b/application/common/model/Attachment.php index 79878c6..2149aec 100644 --- a/application/common/model/Attachment.php +++ b/application/common/model/Attachment.php @@ -21,4 +21,13 @@ class Attachment extends Model return strtotime($value); } + protected static function init() + { + // 如果已经上传该资源,则不再记录 + self::beforeInsert(function ($model) { + if (self::where('url', '=', $model['url'])->find()) { + return false; + } + }); + } } -- libgit2 0.24.0