/** * @param TransactionJournal $journal * @param string $dateField * * @return string */ public static function dateAsString(TransactionJournal $journal, string $dateField = '') : string { if ($dateField === '') { return $journal->date->format('Y-m-d'); } if (!is_null($journal->{$dateField}) && $journal->{$dateField} instanceof Carbon) { // make field NULL $carbon = clone $journal->{$dateField}; $journal->{$dateField} = null; $journal->save(); // create meta entry $journal->setMeta($dateField, $carbon); // return that one instead. return $carbon->format('Y-m-d'); } $metaField = $journal->getMeta($dateField); if (!is_null($metaField)) { $carbon = new Carbon($metaField); return $carbon->format('Y-m-d'); } return ''; }