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

pull/102/head
灰大狼 2019-03-03 16:06:17 +08:00
parent d5bdcd1cd6
commit 7a3fa9d6c1
1 changed files with 9 additions and 0 deletions

View File

@ -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;
}
});
}
}