Skip to content

Commit

Permalink
address corrections on AuditableModel
Browse files Browse the repository at this point in the history
  • Loading branch information
pachonjcl committed Jun 10, 2024
1 parent 3dee507 commit 34740e5
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@ public function __invoke(Request $request, AuditableModel $auditable)
->orderBy('created_at', 'desc')
->get();

$auditStatuses->map(function ($auditStatus) use ($auditable) {
$auditStatus->entity_name = $auditable->name;

return $auditStatus;
});
foreach ($auditStatuses as $auditStatus) {
$auditStatus->entity_name = $auditable->getAuditableNameAttribute();
}

return AuditStatusResource::collection($auditStatuses);
}
Expand Down
3 changes: 3 additions & 0 deletions app/Models/V2/AuditableModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@

interface AuditableModel
{
public function auditStatuses();

public function getAuditableNameAttribute();
}
5 changes: 5 additions & 0 deletions app/Models/V2/Projects/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,11 @@ public function auditStatuses(): MorphMany
return $this->morphMany(AuditStatus::class, 'auditable');
}

public function getAuditableNameAttribute(): string
{
return $this->name;
}

/**
* @return HasManyThrough A relation for all site reports associated with this project that is for an approved
* site, and has a report status past due/started (has been submitted).
Expand Down
5 changes: 5 additions & 0 deletions app/Models/V2/Sites/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -370,4 +370,9 @@ public function auditStatuses(): MorphMany
{
return $this->morphMany(AuditStatus::class, 'auditable');
}

public function getAuditableNameAttribute(): string
{
return $this->name;
}
}
5 changes: 5 additions & 0 deletions app/Models/V2/Sites/SitePolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public function auditStatuses(): MorphMany
{
return $this->morphMany(AuditStatus::class, 'auditable');
}

public function getAuditableNameAttribute(): string
{
return $this->poly_name;
}
}

0 comments on commit 34740e5

Please sign in to comment.