Bladeren bron

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

灰大狼 6 jaren geleden
bovenliggende
commit
7a3fa9d6c1
1 gewijzigde bestanden met toevoegingen van 9 en 0 verwijderingen
  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;
+            }
+        });
+    }
 }