소스 검색

修改Attachment模型,防止同名文件重复生成记录。

灰大狼 6 년 전
부모
커밋
7a3fa9d6c1
1개의 변경된 파일9개의 추가작업 그리고 0개의 파일을 삭제
  1. 9 0
      application/common/model/Attachment.php

+ 9 - 0
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;
+            }
+        });
+    }
 }