diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/postsController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/postsController.php index 45503a2c4..f80ac552a 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/postsController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/postsController.php @@ -38,10 +38,19 @@ class postsController extends Controller public function show($locale,$id){ - $data = $this->Post::with('views')->find($id); + $post = $this->Post::find($id); - if ($data){ - return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]); + if(!is_null($post)) { + $obj = Db::table('vdomah_blogviews_views') + ->where('post_id', $post->getKey()); + + if ($obj->count() > 0) { + $obj = $obj->first(); + $post['veiws'] = $obj->views; + } + } + if ($post){ + return $this->helpers->apiArrayResponseBuilder(200, 'success', [$post]); } else { return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); }