getType(new CommentPost); } public function query(): Builder { return CommentPost::query() ->where('type', CommentPost::$type) ->with('discussion'); } public static function savingOn(Dispatcher $events, callable $callable) { $events->listen(Posted::class, function (Posted $event) use ($callable) { $callable($event->post); }); } public static function deletingOn(Dispatcher $events, callable $callable) { $events->listen(Deleted::class, function (Deleted $event) use ($callable) { $callable($event->post); }); } /** * @param CommentPost $model * @return Document */ public function toDocument(Model $model): Document { $document = new Document([ 'type' => $this->type(), 'id' => $this->type() . ':' . $model->id, 'content' => $model->content, 'created_at' => $model->created_at?->toAtomString(), 'updated_at' => $model->edited_at?->toAtomString(), 'is_private' => $model->is_private, 'user_id' => $model->user_id, 'groups' => $this->groupsForDiscussion($model->discussion) ]); if ($this->extensionEnabled('fof-byobu')) { $document['recipient_users'] = $model->discussion->recipientUsers->pluck('id')->toArray(); $document['recipient_groups'] = $model->discussion->recipientGroups->pluck('id')->toArray(); } return $document; } }