Add identity_type and guardian relationship to members
- Add identity_type field (patient/parent) to distinguish 病友/家長 - Add guardian_member_id for parent-child relationships - Add guardian() and dependents() relationships - Add isPatient(), isParent() helper methods - Add identity_type_label accessor Data updated: - 47 members set as patient, 4 as parent - 25 members with approved disability, 26 without - 張序 linked to guardian 張誠駿 - Payment amounts corrected based on 2024 accounting records Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -30,6 +30,10 @@ class Member extends Model
|
|||||||
const DISABILITY_STATUS_APPROVED = 'approved';
|
const DISABILITY_STATUS_APPROVED = 'approved';
|
||||||
const DISABILITY_STATUS_REJECTED = 'rejected';
|
const DISABILITY_STATUS_REJECTED = 'rejected';
|
||||||
|
|
||||||
|
// Identity type constants (病友/家長)
|
||||||
|
const IDENTITY_PATIENT = 'patient'; // 病友
|
||||||
|
const IDENTITY_PARENT = 'parent'; // 家長/父母
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'user_id',
|
'user_id',
|
||||||
'full_name',
|
'full_name',
|
||||||
@@ -47,6 +51,8 @@ class Member extends Model
|
|||||||
'membership_expires_at',
|
'membership_expires_at',
|
||||||
'membership_status',
|
'membership_status',
|
||||||
'membership_type',
|
'membership_type',
|
||||||
|
'identity_type',
|
||||||
|
'guardian_member_id',
|
||||||
'disability_certificate_path',
|
'disability_certificate_path',
|
||||||
'disability_certificate_status',
|
'disability_certificate_status',
|
||||||
'disability_verified_by',
|
'disability_verified_by',
|
||||||
@@ -72,6 +78,50 @@ class Member extends Model
|
|||||||
return $this->hasMany(MembershipPayment::class);
|
return $this->hasMany(MembershipPayment::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 監護人(父母)
|
||||||
|
*/
|
||||||
|
public function guardian()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Member::class, 'guardian_member_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 被監護人(子女)
|
||||||
|
*/
|
||||||
|
public function dependents()
|
||||||
|
{
|
||||||
|
return $this->hasMany(Member::class, 'guardian_member_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否為病友
|
||||||
|
*/
|
||||||
|
public function isPatient(): bool
|
||||||
|
{
|
||||||
|
return $this->identity_type === self::IDENTITY_PATIENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否為家長/父母
|
||||||
|
*/
|
||||||
|
public function isParent(): bool
|
||||||
|
{
|
||||||
|
return $this->identity_type === self::IDENTITY_PARENT;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 取得身份類型標籤
|
||||||
|
*/
|
||||||
|
public function getIdentityTypeLabelAttribute(): string
|
||||||
|
{
|
||||||
|
return match ($this->identity_type) {
|
||||||
|
self::IDENTITY_PATIENT => '病友',
|
||||||
|
self::IDENTITY_PARENT => '家長/父母',
|
||||||
|
default => '未設定',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 關聯的收入記錄
|
* 關聯的收入記錄
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* Adds identity_type (病友/家長) and guardian relationship fields.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('members', function (Blueprint $table) {
|
||||||
|
// 身份類型:病友 or 家長/父母
|
||||||
|
$table->string('identity_type')->nullable()->after('membership_type');
|
||||||
|
|
||||||
|
// 監護人關係(未成年人指向其父母的 member_id)
|
||||||
|
$table->foreignId('guardian_member_id')->nullable()->after('identity_type')
|
||||||
|
->constrained('members')->nullOnDelete();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('members', function (Blueprint $table) {
|
||||||
|
$table->dropForeign(['guardian_member_id']);
|
||||||
|
$table->dropColumn(['identity_type', 'guardian_member_id']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user