Skip to content

Commit

Permalink
fix project resources
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghelupu17 committed Dec 12, 2023
1 parent 04cf11a commit 5ab0a86
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/Http/Resources/Project/ShowProjectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function toArray(Request $request): array
'donations' => [
'target' => money_format($this->target_budget),
'total' => money_format($this->total_donations),
'count' => $this->donations_count,
'count' => $this->approved_donations_count,
'percentage' => $this->percentage,
],
'championship' => [
Expand Down
9 changes: 8 additions & 1 deletion app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Concerns\HasSlug;
use App\Concerns\HasVolunteers;
use App\Concerns\LogsActivityForApproval;
use App\Enums\EuPlatescStatus;
use App\Enums\ProjectStatus;
use App\Traits\HasProjectStatus;
use Embed\Embed;
Expand Down Expand Up @@ -80,6 +81,7 @@ class Project extends Model implements HasMedia

protected $withCount = [
'donations',
'approvedDonations',
];

public function registerMediaCollections(): void
Expand Down Expand Up @@ -124,6 +126,11 @@ public function donations(): HasMany
return $this->hasMany(Donation::class);
}

public function approvedDonations(): HasMany
{
return $this->donations()->where('status', EuPlatescStatus::CHARGED);
}

public function stages(): BelongsToMany
{
return $this->belongsToMany(ChampionshipStage::class);
Expand All @@ -149,7 +156,7 @@ public function categories(): BelongsToMany

public function getTotalDonationsAttribute(): int
{
return (int) $this->donations->sum('amount');
return (int) $this->approvedDonations->sum('amount');
}

public function getCoverImageAttribute(): string
Expand Down

0 comments on commit 5ab0a86

Please sign in to comment.