diff --git a/app/Models/Study.php b/app/Models/Study.php index d9d464f..4af6288 100644 --- a/app/Models/Study.php +++ b/app/Models/Study.php @@ -4,6 +4,7 @@ use App\Models\Enums\ReportStatus; use App\Models\Enums\StudyLevelStatus; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; class Study extends BaseModel @@ -19,4 +20,14 @@ public function history(): HasOne { return $this->hasOne(StudyHistory::class); } + + public function attachments(): HasMany + { + return $this->hasMany(StudyAttachment::class); + } + + public function reports(): HasMany + { + return $this->hasMany(StudyReport::class); + } } diff --git a/app/Models/StudyNote.php b/app/Models/StudyNote.php index 1166fad..d47f715 100644 --- a/app/Models/StudyNote.php +++ b/app/Models/StudyNote.php @@ -2,6 +2,4 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Model; - -class StudyNote extends Model {} +class StudyNote extends BaseModel {} diff --git a/app/Models/Template.php b/app/Models/Template.php index 8eb4d10..fa6db4c 100644 --- a/app/Models/Template.php +++ b/app/Models/Template.php @@ -2,4 +2,17 @@ namespace App\Models; -class Template extends BaseModel {} +use Illuminate\Database\Eloquent\Relations\BelongsTo; + +class Template extends BaseModel +{ + public function owner(): BelongsTo + { + return $this->belongsTo(User::class, 'owner_id'); + } + + public function category(): BelongsTo + { + return $this->belongsTo(TemplateCategory::class, 'category_id'); + } +} diff --git a/database/migrations/2024_12_28_043818_create_study_notes_table.php b/database/migrations/2024_12_28_043818_create_study_notes_table.php index 94c9414..719554c 100644 --- a/database/migrations/2024_12_28_043818_create_study_notes_table.php +++ b/database/migrations/2024_12_28_043818_create_study_notes_table.php @@ -12,8 +12,8 @@ public function up(): void { Schema::create('study_notes', function (Blueprint $table) { $table->id(); - $table->foreignIdFor(Study::class)->constrained()->onDelete('cascade'); - $table->foreignIdFor(User::class)->nullable()->constrained()->onDelete('cascade'); + $table->foreignIdFor(Study::class)->constrained()->cascadeOnDelete(); + $table->foreignIdFor(User::class)->nullable()->constrained()->cascadeOnDelete(); $table->string('title')->nullable(); $table->longText('content'); $table->timestamps(); diff --git a/database/migrations/2024_12_28_051451_create_study_reports_table.php b/database/migrations/2024_12_28_051451_create_study_reports_table.php index aafb925..e3857c3 100644 --- a/database/migrations/2024_12_28_051451_create_study_reports_table.php +++ b/database/migrations/2024_12_28_051451_create_study_reports_table.php @@ -14,8 +14,9 @@ public function up(): void Schema::create('study_reports', function (Blueprint $table) { $table->id(); $table->unsignedTinyInteger('report_status')->default(ReportStatus::Pending->value); - $table->foreignIdFor(Study::class)->index()->constrained()->onDelete('cascade'); - $table->foreignIdFor(User::class)->index()->constrained()->onDelete('cascade'); + $table->foreignIdFor(Study::class)->index()->constrained()->cascadeOnDelete(); + $table->foreignIdFor(User::class, 'radiologist_id')->index()->constrained()->cascadeOnDelete(); + $table->string('report_title')->nullable(); $table->string('file_path'); $table->string('pdf_path')->nullable(); $table->timestamps();