morphTo(); } /** * Get the account record associated with the invitation. * * @return BelongsTo */ public function account() { return $this->belongsTo(Account::class); } /** * Adds a new entry in the journal. * @param mixed $resourceToLog */ public function add($resourceToLog) { $this->account_id = $resourceToLog->account_id; $this->date = $resourceToLog->date ?? now(); $this->journalable_id = $resourceToLog->id; $this->journalable_type = get_class($resourceToLog); $this->save(); return $this; } /** * Get the information about the object represented by the Journal Entry. * @return array */ public function getObjectData() { $type = $this->journalable_type; // Instantiating the object $correspondingObject = (new $type)::findOrFail($this->journalable_id); return $correspondingObject->getInfoForJournalEntry(); } }