'文字', self::TYPE_2 => '图片', self::TYPE_3 => '视频', ]; public $category_id = 0; public $thumb = ''; protected $casts = ['cover'=>'array','comment_tag'=>'array']; protected $appends = ['category_id', 'thumb']; public function getCategoryIdAttribute() { return $this->attributes['second_id'] ? $this->attributes['second_id'] : $this->attributes['first_id']; } public function getThumbAttribute() { return $this->cover ? asset('storage/'.$this->cover[0]) : ''; } public function firstCloumn(){ return $this->belongsTo(SpecialistCloumn::class, 'first_id', 'id'); } public function secondCloumn(){ return $this->belongsTo(SpecialistCloumn::class, 'second_id', 'id'); } public function leaveMessage(){ return $this->hasMany(SpecialistInfoLeaveMessage::class, 'specialist_infos_id', 'id') ->with( ["user"=>function($with){ $with->select(['id','wx_nickname','wx_headimgurl','third_up_nickname','third_up_headimg']); } ] ); } protected static function booted() { //回调删除操作 static::deleting(function ($model) { BrowseRecord::query()->where( array( "column"=>BrowseRecord::COLUMN_3, "object_id"=>$model->id ) )->delete(); SpecialistInfosAssociation::query()->where( array( "association_id"=>$model->id, ) )->delete(); }); } }