Post = $Post; $this->helpers = $helpers; } public function index(){ $path = Config::get('app.cdn').Config::get('cms.storage.media.path'); $data = $this->Post::with(['categories:id,name'])->listFrontEnd([ 'page' => input('page'), 'sort' => input('sort')??'published_at desc', 'perPage' => input('count'), 'search' => trim(input('search')), 'category' => input('category'), 'date' => input('date'), 'published' => true, 'select' => ['id','title','published_at',DB::raw("IF(featured_image<>'',concat('$path',featured_image),featured_image) as main_image")] ]); return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); } public function show($locale,$id){ $post = $this->Post::find($id,['id','content_html','author']); if(!is_null($post)) { $obj = Db::table('vdomah_blogviews_views') ->where('post_id', $post->getKey()); if ($obj->count() > 0) { $row = $obj->first(); $views = $row->views + rand(1,10);; $obj->update(['views' => $views]); $post['views'] = $row->views; } else { Db::table('vdomah_blogviews_views')->insert([ 'post_id' => $post->getKey(), 'views' => rand(1,10) ]); } } 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']); } } }