/** * @param PrepareApiData $event */ public function loadTagsRelationship(PrepareApiData $event) { // Expose the complete tag list to clients by adding it as a // relationship to the /api/forum endpoint. Since the Forum model // doesn't actually have a tags relationship, we will manually load and // assign the tags data to it using an event listener. if ($event->isController(ShowForumController::class)) { $event->data['tags'] = Tag::whereVisibleTo($event->actor)->with('lastDiscussion')->get(); } }
public function loadTagsRelationship(WillSerializeData $event) { // Expose the complete tag list to clients by adding it as a // relationship to the /api/forum endpoint. Since the Forum model // doesn't actually have a tags relationship, we will manually load and // assign the tags data to it using an event listener. if ($event->action instanceof Forum\ShowAction) { $forum = $event->data; $query = Tag::whereVisibleTo($event->request->actor); $forum->tags = $query->with('lastDiscussion')->get(); $forum->tags_ids = $forum->tags->lists('id'); } }
/** * {@inheritdoc} */ protected function data(ServerRequestInterface $request, Document $document) { $actor = $request->getAttribute('actor'); return $this->tags->whereVisibleTo($actor)->withStateFor($actor)->get(); }