api surat views
This commit is contained in:
parent
af44985c1c
commit
112539e3d7
|
|
@ -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']);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue