From da0d3c0db7c6d1557a7e18b468f8f7b30d58d725 Mon Sep 17 00:00:00 2001 From: Lupu Gheorghe Date: Mon, 9 Oct 2023 15:55:53 +0300 Subject: [PATCH] fix empty strings --- app/Models/Project.php | 6 ++++++ app/Traits/HasProjectStatus.php | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/Models/Project.php b/app/Models/Project.php index 7b777032..ce39122d 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -141,6 +141,9 @@ public function getCoverImageAttribute(): string public function getPercentageAttribute(): float { + if ($this->target_budget == 0) { + return 0; + } return min(100, $this->total_donations / $this->target_budget * 100); } @@ -163,6 +166,9 @@ public function getIsActiveAttribute(): bool public function getIsEndingSoonAttribute(): bool { + if (empty($this->end)) { + return false; + } return $this->end->diffInDays(today()) <= 5; } } diff --git a/app/Traits/HasProjectStatus.php b/app/Traits/HasProjectStatus.php index 67311f66..bc4e72ce 100644 --- a/app/Traits/HasProjectStatus.php +++ b/app/Traits/HasProjectStatus.php @@ -63,10 +63,11 @@ public function scopeWhereStartsSoon(): Builder ->whereDate('start', '>=', now()) ->orderBy('start'); } + public function scopeStatusIs($status): Builder { // dd($status); - return match ($status){ + return match ($status) { 'pending' => $this->whereIsPending(), 'approved' => $this->whereIsApproved(), 'rejected' => $this->whereIsRejected(),