From 95d44eea1501ccedf10723decd934a0e08698a99 Mon Sep 17 00:00:00 2001 From: Kamieljv Date: Fri, 6 Sep 2024 17:08:08 +0200 Subject: [PATCH] Fixed getAfgelopenAttribute --- app/Models/Actie.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/app/Models/Actie.php b/app/Models/Actie.php index 6426d1a7..cb7beedb 100755 --- a/app/Models/Actie.php +++ b/app/Models/Actie.php @@ -226,21 +226,20 @@ public function report() return $this->hasOne(Report::class)->without('actie'); } - public function getAfgelopenAttribute() - { - return Date::parse($this->end_date . " " . $this->end_time)->timestamp < time(); - } - public function getPublishedAttribute() { return $this->status === "PUBLISHED"; } - - public function scopePublished($query) + + public function getAfgelopenAttribute() { - return $query->where('status', 'PUBLISHED'); + if ($this->end_time === null) { + // if end_time is not set, take the end of the day + return Date::parse($this->end_date . " " . "23:59:59")->timestamp < time(); + } + return Date::parse($this->end_date . " " . $this->end_time)->timestamp < time(); } - + public function scopeNietAfgelopen($query) { // check if end_time is defined @@ -248,6 +247,11 @@ public function scopeNietAfgelopen($query) ->orWhereRaw("(end_time is NULL AND STR_TO_DATE(end_date, '%Y-%m-%d') >= '" . Date::now()->toDateString() . "')"); } + public function scopePublished($query) + { + return $query->where('status', 'PUBLISHED'); + } + public function publish() { $this->status = 'PUBLISHED';