*/ protected $fillable = []; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = []; protected $casts = [ 'created_at' => 'datetime:Y-m-d H:i:s', 'updated_at' => 'datetime:Y-m-d H:i:s', ]; public function getMateConditionAttribute(){ if(is_string($this->attributes['mate_condition'])){ return $this->attributes['mate_condition'] = json_decode($this->attributes['mate_condition']); }else{ return $this->attributes['mate_condition']; } } public function getAffectiveStateAttribute($affective_state){ switch ($affective_state){ case 1: $value = '未婚'; break; case 2: $value = '离异无孩'; break; case 3: $value = '离异带孩'; break; case 4: $value = '离异不带孩'; break; case 5: $value = '丧偶'; break; default: $value = null; break; } return $value; } public function setAffectiveStateAttribute($affective_state){ switch ($affective_state){ case '未婚': $value = 1; break; case '离异无孩': $value = 2; break; case '离异带孩': $value = 3; break; case '离异不带孩': $value = 4; break; case '丧偶': $value = 5; break; default: $value = 0; break; } $this->attributes['affective_state'] = $value; } public function love_user(){ return $this->belongsTo(User::class,'love_user_id','id'); } public function love_user_profile(){ return $this->belongsTo(ProfileCourtship::class,'love_user_id','user_id'); } }