refactor: update relationships in models to include withTrashed() for soft deletes, ensuring proper handling of related records

This commit is contained in:
Yoga Pangestu 2026-07-10 11:07:07 +07:00
parent 709eb76873
commit fe5dfd382f
29 changed files with 49 additions and 49 deletions

View File

@ -130,7 +130,7 @@ public function registerMediaCollections(): void
// 5. Relation
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
return $this->belongsTo(Employee::class)->withTrashed();
}
public function payrollAdjustments(): HasMany

View File

@ -191,7 +191,7 @@ public function cashAccount(): BelongsTo
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function order(): HasOne

View File

@ -105,7 +105,7 @@ public function ensureEditable(): void
// 6. Relation
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function materials(): HasMany
@ -130,6 +130,6 @@ public function results(): HasMany
public function submittedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'submitted_by_id');
return $this->belongsTo(User::class, 'submitted_by_id')->withTrashed();
}
}

View File

@ -81,21 +81,21 @@ private function formatQuantityInput(float|string|null $value): string
// 5. Relation
public function cutting(): BelongsTo
{
return $this->belongsTo(Cutting::class);
return $this->belongsTo(Cutting::class)->withTrashed();
}
public function rawMaterialPrice(): BelongsTo
{
return $this->belongsTo(RawMaterialPrice::class);
return $this->belongsTo(RawMaterialPrice::class)->withTrashed();
}
public function combination(): BelongsTo
{
return $this->belongsTo(CuttingMaterialCombination::class, 'combination_id');
return $this->belongsTo(CuttingMaterialCombination::class, 'combination_id')->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -24,12 +24,12 @@ protected function casts(): array
public function cutting(): BelongsTo
{
return $this->belongsTo(Cutting::class);
return $this->belongsTo(Cutting::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
public function materials(): HasMany

View File

@ -28,16 +28,16 @@ protected function casts(): array
// 3. Relation
public function cutting(): BelongsTo
{
return $this->belongsTo(Cutting::class);
return $this->belongsTo(Cutting::class)->withTrashed();
}
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -53,11 +53,11 @@ public function typeLabel(): Attribute
// 4. Relation
public function cutting(): BelongsTo
{
return $this->belongsTo(Cutting::class);
return $this->belongsTo(Cutting::class)->withTrashed();
}
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
}

View File

@ -118,6 +118,6 @@ public function payrolls(): HasMany
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -201,7 +201,7 @@ public function cashTransaction(): BelongsTo
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
return $this->belongsTo(Employee::class)->withTrashed();
}
public function paidBy(): BelongsTo

View File

@ -56,6 +56,6 @@ public function employeeAdvance(): BelongsTo
public function paidBy(): BelongsTo
{
return $this->belongsTo(User::class, 'paid_by_id');
return $this->belongsTo(User::class, 'paid_by_id')->withTrashed();
}
}

View File

@ -64,11 +64,11 @@ public function registerMediaCollections(): void
// 5. Relation
public function cashTransaction(): BelongsTo
{
return $this->belongsTo(CashTransaction::class);
return $this->belongsTo(CashTransaction::class)->withTrashed();
}
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
}

View File

@ -158,7 +158,7 @@ public static function canSubmit(User $user): bool
// 6. Relation
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
return $this->belongsTo(Employee::class)->withTrashed();
}
public function verifiedBy(): BelongsTo

View File

@ -45,6 +45,6 @@ public function markAsRead(): void
// 4. Relation
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -289,17 +289,17 @@ public function registerMediaCollections(): void
// 6. Relation
public function cashTransaction(): BelongsTo
{
return $this->belongsTo(CashTransaction::class);
return $this->belongsTo(CashTransaction::class)->withTrashed();
}
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function customer(): BelongsTo
{
return $this->belongsTo(Customer::class);
return $this->belongsTo(Customer::class)->withTrashed();
}
public function items(): HasMany
@ -309,6 +309,6 @@ public function items(): HasMany
public function marketing(): BelongsTo
{
return $this->belongsTo(User::class, 'marketing_id');
return $this->belongsTo(User::class, 'marketing_id')->withTrashed();
}
}

View File

@ -67,16 +67,16 @@ public function unitPriceFormatted(): Attribute
// 4. Relation
public function order(): BelongsTo
{
return $this->belongsTo(Order::class);
return $this->belongsTo(Order::class)->withTrashed();
}
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -184,11 +184,11 @@ public function subject(): MorphTo
public function submittedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'submitted_by_id');
return $this->belongsTo(User::class, 'submitted_by_id')->withTrashed();
}
public function verifiedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'verified_by_id');
return $this->belongsTo(User::class, 'verified_by_id')->withTrashed();
}
}

View File

@ -163,7 +163,7 @@ public function cashTransaction(): BelongsTo
public function employee(): BelongsTo
{
return $this->belongsTo(Employee::class);
return $this->belongsTo(Employee::class)->withTrashed();
}
public function paidBy(): BelongsTo

View File

@ -83,7 +83,7 @@ public function attendance(): BelongsTo
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function payroll(): BelongsTo

View File

@ -77,7 +77,7 @@ public function isOpen(): bool
// 6. Relation
public function closedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'closed_by_id');
return $this->belongsTo(User::class, 'closed_by_id')->withTrashed();
}
public function payrolls(): HasMany

View File

@ -44,6 +44,6 @@ public function priceInput(): Attribute
// 4. Relation
public function variant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class, 'variant_id');
return $this->belongsTo(ProductVariant::class, 'variant_id')->withTrashed();
}
}

View File

@ -94,6 +94,6 @@ public function prices(): HasMany
public function product(): BelongsTo
{
return $this->belongsTo(Product::class);
return $this->belongsTo(Product::class)->withTrashed();
}
}

View File

@ -114,6 +114,6 @@ public function pendingOwnerVerificationRequest(): MorphOne
public function supplier(): BelongsTo
{
return $this->belongsTo(Supplier::class);
return $this->belongsTo(Supplier::class)->withTrashed();
}
}

View File

@ -80,16 +80,16 @@ public function unitPriceFormatted(): Attribute
// 4. Relation
public function purchase(): BelongsTo
{
return $this->belongsTo(Purchase::class);
return $this->belongsTo(Purchase::class)->withTrashed();
}
public function rawMaterialPrice(): BelongsTo
{
return $this->belongsTo(RawMaterialPrice::class);
return $this->belongsTo(RawMaterialPrice::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -89,6 +89,6 @@ public function purchaseItems(): HasMany
public function rawMaterial(): BelongsTo
{
return $this->belongsTo(RawMaterial::class);
return $this->belongsTo(RawMaterial::class)->withTrashed();
}
}

View File

@ -23,6 +23,6 @@ public function rejectable(): MorphTo
public function rejectedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'rejected_by_id');
return $this->belongsTo(User::class, 'rejected_by_id')->withTrashed();
}
}

View File

@ -29,11 +29,11 @@ protected function casts(): array
// 2. Relation
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}

View File

@ -89,7 +89,7 @@ public function statusLabel(): Attribute
// 5. Relation
public function createdBy(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by_id');
return $this->belongsTo(User::class, 'created_by_id')->withTrashed();
}
public function items(): HasMany
@ -99,6 +99,6 @@ public function items(): HasMany
public function verifiedBy(): BelongsTo
{
return $this->belongsTo(User::class, 'verified_by_id');
return $this->belongsTo(User::class, 'verified_by_id')->withTrashed();
}
}

View File

@ -43,11 +43,11 @@ public function getVariantNameAttribute(): string
// 3. Relation
public function productVariant(): BelongsTo
{
return $this->belongsTo(ProductVariant::class);
return $this->belongsTo(ProductVariant::class)->withTrashed();
}
public function stokOpname(): BelongsTo
{
return $this->belongsTo(StokOpname::class);
return $this->belongsTo(StokOpname::class)->withTrashed();
}
}

View File

@ -87,6 +87,6 @@ public function registerMediaCollections(): void
// 5. Relation
public function user(): BelongsTo
{
return $this->belongsTo(User::class);
return $this->belongsTo(User::class)->withTrashed();
}
}