1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- <?php
- namespace app\common\model;
- use think\Collection;
- use think\Model;
- use traits\model\SoftDelete;
- /**
- * 短信验证码
- * @property Collection|Model commentable
- */
- class Comment Extends Model
- {
- use SoftDelete;
- protected $deleteTime='deleted_at';
- // 开启自动写入时间戳字段
- protected $autoWriteTimestamp = true;
- protected $createTime='created_at';
- protected $updateTime=false;
- protected $hidden=[
- 'deleted_at',
- 'commentable_id',
- ];
- public static $alias=[
- 'video'=>Video::class,
- ];
- protected $append=[
- ];
- public function commentable(){
- return $this->morphTo('commentable',self::$alias);
- }
- public function user(){
- return $this->belongsTo(User::class);
- }
- /** system */
- protected static function init()
- {
- self::afterInsert(function (self $comment){
- if($comment->commentable_type=='video'){
- $info=Video::find($comment->commentable_id);
- $info && $info->setInc('comment_num');
- }
- });
- self::afterDelete(function (self $comment){
- });
- }
- }
|