api surat views

This commit is contained in:
merdan 2021-05-12 14:40:08 +05:00
parent af44985c1c
commit 112539e3d7
1 changed files with 12 additions and 3 deletions

View File

@ -38,10 +38,19 @@ class postsController extends Controller
public function show($locale,$id){ public function show($locale,$id){
$data = $this->Post::with('views')->find($id); $post = $this->Post::find($id);
if ($data){ if(!is_null($post)) {
return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]); $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 { } else {
return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']);
} }