作者 灰大狼

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

@@ -21,4 +21,13 @@ class Attachment extends Model @@ -21,4 +21,13 @@ class Attachment extends Model
21 return strtotime($value); 21 return strtotime($value);
22 } 22 }
23 23
  24 + protected static function init()
  25 + {
  26 + // 如果已经上传该资源,则不再记录
  27 + self::beforeInsert(function ($model) {
  28 + if (self::where('url', '=', $model['url'])->find()) {
  29 + return false;
  30 + }
  31 + });
  32 + }
24 } 33 }