1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php
- namespace App\Models;
- use Illuminate\Support\Facades\Log;
- class SpecialistInfo extends SoftBaseModel
- {
- /**
- * 类别 1:文字
- * @var integer
- */
- const TYPE_1 = 1;
- /**
- * 类别 2:图片
- * @var integer
- */
- const TYPE_2 = 2;
- /**
- * 类别 3:视频
- * @var integer
- */
- const TYPE_3 = 3;
- static public $typeMap = [
- self::TYPE_1 => '文字',
- 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();
- });
- }
- }
|