Post = $Post; $this->helpers = $helpers; } //postes list 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'), 'typePost' => input('typePost'), 'postGroup' => input('group'), 'published' => true, 'featured' => input('featured') == true ? 1 : 0, 'select' => ['id','title','slug','published_at',DB::raw("IF(featured_image<>'',concat('$path',featured_image),featured_image) as main_image")] ]); if($data){ $data->each(function ($item, $key) { $item->url = $this->pageUrl('post',['id'=>$item->id,'slug'=>$item->slug]); }); } return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); } //posts item public function show($locale,$id){ $post = $this->Post::find($id,['id','content_html','author','slug']); if(!is_null($post)) { $post->url = $this->pageUrl('post',['id'=>$post->id,'slug'=>$post->slug]); $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) ]); } return $this->helpers->apiArrayResponseBuilder(200, 'success', [$post]); } else { return $this->helpers->apiArrayResponseBuilder(404, 'not found', ['error' => 'Resource id=' . $id . ' could not be found']); } } }