I have created php api that gets flarum database when output has empty id
link router api: domain/api/of/globalStats
{
"data": [{
"type": "global_stats",
"id": "",
"attributes": {
"discussion_count": 95,
"user_count": 12,
"comment_post_count": 166,
"tags_count": 19,
"blog_count": 21,
"group_count": 5
}
}]
}
php api Controller
protected function data(ServerRequestInterface $request, Document $document) {
$viewstats = [
'discussion_count' => '95',
'user_count' => '12',
'comment_post_count' => '166',
'tags_count' => '19',
'blog_count' => '21',
'group_count' => '5',
];
//$viewHistory = 'stats';
if (empty($viewHistory)) {
return ;
}
$viewHistory[] =
$viewstats
;
return $viewHistory;
}
php api Serializer
protected function getDefaultAttributes($viewHistory) {
return $viewHistory;
}
I want to assign an id value for example: id = 'stats', what should I do?
The API outputs correctly as follows:
{
"data": [{
"type": "global_stats",
"id": "stats",
"attributes": {
"discussion_count": 95,
"user_count": 12,
"comment_post_count": 166,
"tags_count": 19,
"blog_count": 21,
"group_count": 5
}
}]
}
or
{
"data": {
"type": "global_stats",
"id": "stats",
"attributes": {
"discussion_count": 95,
"user_count": 12,
"comment_post_count": 166,
"tags_count": 19,
"blog_count": 21,
"group_count": 5
}
}
}
@clarkwinkelmann @luceos Help me