From 642446e592133a81584d1d5e72b9f25c68e28516 Mon Sep 17 00:00:00 2001 From: Deon George Date: Mon, 13 Jun 2022 19:58:53 +1000 Subject: [PATCH] Cast Invoice::reminders to json --- app/Models/Invoice.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 9c5f4dd..aec3ad5 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -35,6 +35,10 @@ class Invoice extends Model implements IDs { use PushNew,ScopeActive; + protected $casts = [ + 'reminders'=>'json', + ]; + protected $dates = [ 'due_at', ]; @@ -414,16 +418,17 @@ class Invoice extends Model implements IDs /** * @param string $key - * @return string + * @return array * @todo Ugly hack to update reminders */ - public function reminders(string $key) { - $r = json_decode($this->reminders); - + public function reminders(string $key): array + { + $r = $this->reminders; if (! Arr::get($r,$key)) { $r[$key] = time(); - return json_encode($r); } + + return $r; } /** @@ -432,7 +437,8 @@ class Invoice extends Model implements IDs * @param array $options * @return bool */ - public function save(array $options = []) { + public function save(array $options = []) + { // Automatically set the date_due attribute for new records. if (! $this->exists AND ! $this->due_at) { $this->due_at = $this->items->min('start_at');