diff --git a/framework/core/src/Api/Actions/Forum/ShowAction.php b/framework/core/src/Api/Actions/Forum/ShowAction.php new file mode 100644 index 000000000..44a80ebbd --- /dev/null +++ b/framework/core/src/Api/Actions/Forum/ShowAction.php @@ -0,0 +1,29 @@ +$relation) ? $model->$relation : $model->$relation()->getResults(); + if (! is_null($model->$relation)) { + $data = $model->$relation; + } else { + $relation = $model->$relation(); + if ($relation instanceof Relation) { + $data = $relation->getResults(); + } else { + $data = $relation->get(); + } + } } elseif ($many) { $relationIds = $relation.'_ids'; $data = $model->$relationIds ?: $model->$relation()->get(['id'])->fetch('id')->all(); diff --git a/framework/core/src/Api/Serializers/ForumSerializer.php b/framework/core/src/Api/Serializers/ForumSerializer.php new file mode 100644 index 000000000..56143f844 --- /dev/null +++ b/framework/core/src/Api/Serializers/ForumSerializer.php @@ -0,0 +1,31 @@ + $forum->title + ]; + + return $this->extendAttributes($forum, $attributes); + } +} diff --git a/framework/core/src/Core/Models/Discussion.php b/framework/core/src/Core/Models/Discussion.php index eb3c72116..d36ec93e4 100755 --- a/framework/core/src/Core/Models/Discussion.php +++ b/framework/core/src/Core/Models/Discussion.php @@ -28,6 +28,8 @@ class Discussion extends Model 'last_post_number' => 'integer' ]; + protected static $relationships = []; + /** * The table associated with the model. * diff --git a/framework/core/src/Core/Models/Forum.php b/framework/core/src/Core/Models/Forum.php index 7996ed5fa..078af04d7 100755 --- a/framework/core/src/Core/Models/Forum.php +++ b/framework/core/src/Core/Models/Forum.php @@ -7,6 +7,8 @@ class Forum extends Model { use Permissible; + protected static $relationships = []; + public function getTitleAttribute() { return Core::config('forum_title'); diff --git a/framework/core/src/Forum/Actions/IndexAction.php b/framework/core/src/Forum/Actions/IndexAction.php index c1d36890b..9e6351880 100644 --- a/framework/core/src/Forum/Actions/IndexAction.php +++ b/framework/core/src/Forum/Actions/IndexAction.php @@ -22,10 +22,18 @@ class IndexAction extends BaseAction public function handle(Request $request, $params = []) { $config = DB::table('config')->whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key'); - $data = []; $session = []; $alert = Session::get('alert'); + $response = app('Flarum\Api\Actions\Forum\ShowAction') + ->handle(new ApiRequest([], $this->actor)) + ->content->toArray(); + + $data = [$response['data']]; + if (isset($response['included'])) { + $data = array_merge($data, $response['included']); + } + if (($user = $this->actor->getUser()) && $user->exists) { $session = [ 'userId' => $user->id, @@ -36,7 +44,7 @@ class IndexAction extends BaseAction ->handle(new ApiRequest(['id' => $user->id], $this->actor)) ->content->toArray(); - $data = [$response['data']]; + $data = array_merge($data, [$response['data']]); if (isset($response['included'])) { $data = array_merge($data, $response['included']); }