/** * Create a new messageData thread, with an optional object reference * * @param array $messageData * @param null $object * @return static * @throws InvalidMessageFormatException * @throws NonParleyableMemberException */ public function discuss(array $messageData, $object = null) { // Make sure we have a subject parameter if (!array_key_exists('subject', $messageData)) { throw new InvalidMessageFormatException("Missing subject from message data attributes"); } // Make sure we have an author parameter if (!array_key_exists('author', $messageData)) { throw new InvalidMessageFormatException('You must specify an author for this Parley Thread'); } // Make sure the author object implements the ParleyableInterface $this->confirmObjectIsParleyable($messageData['author']); // Create a new Parley Thread with its first Message $thread = Thread::create(['subject' => e($messageData['subject'])]); $thread->setInitialMessage($messageData); // Set the reference object if it has been provided in the message data if (array_key_exists('regarding', $messageData)) { $thread->setReferenceObject($messageData['regarding']); } // Set the reference object if it has been passed as a parameter to the discuss method if ($object) { $thread->setReferenceObject($object); } return $thread; }