/** * Creates a postinside a topic * @param Topic $topic * @param Member $member * @param array $data Post data: subject, content. * @return self */ public static function createInTopic($topic, $member, $data) { $post = new static(); $post->topic = $topic; $post->member = $member; $post->subject = array_get($data, 'subject', $topic->subject); $post->content = array_get($data, 'content'); $post->save(); TopicFollow::follow($topic, $member); $member->touchActivity(); return $post; }
/** * Creates a topic and a post inside a channel * @param Channel $channel * @param Member $member * @param array $data Topic and post data: subject, content. * @return self */ public static function createInChannel($channel, $member, $data) { $topic = new static(); $topic->subject = array_get($data, 'subject'); $topic->channel = $channel; $topic->start_member = $member; $post = new Post(); $post->topic = $topic; $post->member = $member; $post->content = array_get($data, 'content'); Db::transaction(function () use($topic, $post) { $topic->save(); $post->save(); }); TopicFollow::follow($topic, $member); $member->touchActivity(); return $topic; }