From 95d44eea1501ccedf10723decd934a0e08698a99 Mon Sep 17 00:00:00 2001 From: Kamieljv Date: Fri, 6 Sep 2024 17:08:08 +0200 Subject: [PATCH 1/2] 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'; From 3036a7d620087eef4242fc9b8a7fc6b577c47eac Mon Sep 17 00:00:00 2001 From: Kamieljv Date: Sat, 14 Sep 2024 15:05:18 +0200 Subject: [PATCH 2/2] Exposed afgelopen attribute on Actie --- app/Models/Actie.php | 1 + resources/views/assets/js/components/partials/Actie.vue | 7 +------ 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/Models/Actie.php b/app/Models/Actie.php index cb7beedb..ceeeaab7 100755 --- a/app/Models/Actie.php +++ b/app/Models/Actie.php @@ -50,6 +50,7 @@ class Actie extends Model */ protected $appends = [ 'link', + 'afgelopen', 'start_end', 'start_unix', '_geoloc', diff --git a/resources/views/assets/js/components/partials/Actie.vue b/resources/views/assets/js/components/partials/Actie.vue index ddcdadb6..09a000fb 100644 --- a/resources/views/assets/js/components/partials/Actie.vue +++ b/resources/views/assets/js/components/partials/Actie.vue @@ -3,7 +3,7 @@ class="flex flex-col overflow-hidden rounded-lg shadow-lg actie relative transition-all ease-out hover:translate-y-[-0.250rem] hover:shadow-[0_0_20px_rgba(0,0,0,0.30)]" typeof="Article" > - + @@ -128,11 +128,6 @@ export default { type: Object, required: true, } - }, - computed: { - isAfgelopen() { - return new Date(this.actie.end_date + " " + this.actie.end_time) < new Date() - } } }