Gender::class, 'treat_at' => 'date', 'birthday' => 'date', 'images' => 'json', ]; protected function age(): Attribute { return new Attribute( get: fn () => $this->birthday ? $this->birthday->diffInYears() : '', ); } protected function sexText(): Attribute { return new Attribute( get: fn () => $this->sex ? $this->sex->text() : '', ); } protected function treatFormat(): Attribute { return new Attribute( get: fn () => $this->treat_at ? $this->treat_at->format('Y-m-d') : '', ); } protected function birthdayFormat(): Attribute { return new Attribute( get: fn () => $this->birthday ? $this->birthday->format('Y-m-d') : '', ); } public function user() { return $this->belongsTo(User::class, 'user_id'); } public function doctor() { return $this->belongsTo(AdminUser::class, 'doctor_id'); } public function inviter() { return $this->belongsTo(AdminUser::class, 'inviter_id'); } public function saler() { return $this->belongsTo(AdminUser::class, 'saler_id'); } public function type() { return $this->belongsTo(Keyword::class, 'type_id'); } public function records() { return $this->hasMany(PatientRecord::class, 'patient_id'); } public function scopeSort($q) { return $q->orderBy('id', 'desc'); } }