Content = $Content; $this->helpers = $helpers; } protected function validateForm($data, $rules) { return Validator::make($data, $rules); } public function index(Request $request) { $dataVal = $request->all(); $data = Post::with(['categories:id,name', 'featured_images']) ->where('published', 1) ->select('id', 'title', 'published_at', 'slug', 'excerpt') ->orderBy('published_at', 'desc') ->with('views') ->paginate($dataVal["per_page"] ?? 6); //$data->translateContext($dataVal["locale"]); if($data){ $data->each(function ($item, $key) use($dataVal) { $item->translateContext($dataVal["locale"] ?? 'ru'); }); } if (count($data) != 0) { // return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); return response()->json($data, 200); } else { return $this->helpers->apiArrayResponseBuilder(404, 'not found data', []); } } public function getPost(Request $request, $id) { $dataVal = $request->all(); $data = Post::with(['categories:id,name', 'featured_images']) ->select('id', 'title', 'published_at', 'slug', 'excerpt', 'content_html', 'meta_title', 'meta_description', 'meta_keywords') ->with('views') ->find($id); if($data){ $obj = Db::table('vdomah_blogviews_views') ->where('post_id', $id); if ($obj->count() > 0) { $row = $obj->first(); // $views = $row->views + rand(1,10);; $views = $row->views + 1;; $obj->update(['views' => $views]); // $data['views'] = $row->views; } else { Db::table('vdomah_blogviews_views')->insert([ 'post_id' => $data->getKey(), 'views' => 1 ]); //$data['views'] = 0; } $data->translateContext($dataVal["locale"] ?? 'ru'); return response()->json($data, 200); //return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]); }else{ return $this->helpers->apiArrayResponseBuilder(404, 'not found data', []); } } }