Post = $Post; $this->helpers = $helpers; } //postes list public function index(){ $path = Config::get('app.cdn').Config::get('cms.storage.media.path'); $filter = [ '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, 'select' => ['id','title','slug', 'featured', 'published_at', 'more_photo','afisha_phone', 'afisha_address', 'afisha_phone_new', DB::raw("IF(featured_image<>'',concat('$path',featured_image),featured_image) as main_image")] ]; if(request()->has('featured')){ $filter['featured'] = true; } $data = $this->Post::with(['categories:id,name'])->listFrontEnd($filter); if($data){ $data->each(function ($item, $key) { $item->url = $this->pageUrl('new/newPost',['id'=>$item->id,'slug'=>$item->slug]); }); } return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); } //posts item public function show($locale,$id){ $path = Config::get('app.cdn').Config::get('cms.storage.media.path'); //$post = $this->Post::find($id,['id','content_html','author','slug', 'afisha_phone', 'afisha_address', 'afisha_phone_new']); $post = $this->Post::where('id', $id)->select('id', 'content_html', 'author', 'title','slug','published_at', 'more_photo','afisha_phone', 'afisha_address', 'afisha_phone_new', DB::raw("IF(featured_image<>'',concat('$path',featured_image),featured_image) as main_image"))->with(['categories:id,name'])->first(); if(!is_null($post)) { $post->url = $this->pageUrl('new/newPost',['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']); } } }