|
@@ -136,6 +136,20 @@ public function scopeLatestVersion(Builder $query): Builder
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ protected static function booted(): void
|
|
|
|
|
+ {
|
|
|
|
|
+ $updateStudentStatus = function (StudentContract $contract): void {
|
|
|
|
|
+ if ($contract->student_id) {
|
|
|
|
|
+ // Use withoutGlobalScopes or just normal relation if no scopes affect it
|
|
|
|
|
+ $contract->student()->first()?->updateStatus();
|
|
|
|
|
+ }
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ static::saved($updateStudentStatus);
|
|
|
|
|
+ static::deleted($updateStudentStatus);
|
|
|
|
|
+ static::restored($updateStudentStatus);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public function derivedFrom(): BelongsTo
|
|
public function derivedFrom(): BelongsTo
|
|
|
{
|
|
{
|
|
|
return $this->belongsTo(self::class, 'derived_from_contract_id');
|
|
return $this->belongsTo(self::class, 'derived_from_contract_id');
|