Cast Invoice::reminders to json

This commit is contained in:
Deon George 2022-06-13 19:58:53 +10:00
parent d1fbb4b42b
commit 642446e592
1 changed files with 12 additions and 6 deletions

View File

@ -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');