morphTo(); } /** * Get the account record associated with the journal entry. * * @return BelongsTo */ public function account() { return $this->belongsTo(Account::class); } /** * Adds a new entry in the journal. * * @param \App\Interfaces\IsJournalableInterface $resourceToLog * @return self */ public static function add(IsJournalableInterface $resourceToLog) : self { $journal = new self; $journal->account_id = $resourceToLog->account_id; $journal->date = now(); if ($resourceToLog instanceof \App\Models\Account\Activity) { $journal->date = $resourceToLog->date_it_happened; } elseif ($resourceToLog instanceof \App\Models\Journal\Entry) { $journal->date = $resourceToLog->attributes['date']; } $journal->save(); $resourceToLog->journalEntries()->save($journal); return $journal; } /** * Update an entry in the journal. * * @param \App\Interfaces\IsJournalableInterface $resourceToLog * @return self */ public function edit(IsJournalableInterface $resourceToLog) : self { if ($resourceToLog instanceof \App\Models\Journal\Entry) { $this->date = $resourceToLog->attributes['date']; } $this->save(); return $this; } /** * Get the information about the object represented by the Journal Entry. * * @return array */ public function getObjectData() { // Instantiating the object /** @var IsJournalableInterface */ $correspondingObject = $this->journalable; return $correspondingObject->getInfoForJournalEntry(); } }