From fa21ac42f30d53104b8866e28a03a424db3c63d4 Mon Sep 17 00:00:00 2001 From: gerchek Date: Thu, 20 Jan 2022 22:00:49 +0500 Subject: [PATCH] update api posts --- .../controllers/api/categoriesController.php | 15 ++++++++++++--- .../controllers/api/postsController.php | 7 ++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/categoriesController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/categoriesController.php index fe537ae..4f238b9 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/categoriesController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/categoriesController.php @@ -7,6 +7,7 @@ use Illuminate\Http\Request; use AhmadFatoni\ApiGenerator\Helpers\Helpers; use Illuminate\Support\Facades\Validator; use RainLab\Blog\Models\Category; +use RainLab\Blog\Models\Post; class categoriesController extends Controller { protected $Category; @@ -21,7 +22,7 @@ class categoriesController extends Controller } public function index(){ -// $data = $this->Post::with(['translations:locale,model_id,attribute_data','categories'])->get(); + // $data = $this->Post::with(['translations:locale,model_id,attribute_data','categories'])->get(); // $data = $this->Category->all()->toArray(); $data = $this->Category::with(['translations:locale,model_id,attribute_data','posts.translations'])->get(); @@ -29,8 +30,16 @@ class categoriesController extends Controller } public function show($id){ -// $data = $this->Post::with(['translations:locale,model_id,attribute_data','categories'])->get(); - $data = $this->Category::with(['translations:locale,model_id,attribute_data','posts.featured_images' , 'posts.translations'])->find($id); + // $input = \Input::all(); + // $pgn=$input['pgn']; + // $data = $this->Post::with(['translations:locale,model_id,attribute_data','categories'])->get(); + $dataaaa = $this->Category::with(['translations:locale,model_id,attribute_data','posts.featured_images' , 'posts.translations'])->find($id); + // $data = Post::where('categories:id', $dataaaa['id'])->get(); + $data = Post::whereHas('categories',function($q) use ($dataaaa) + { + $q->where('id' , $dataaaa['id']); + + })->with(['translations:locale,model_id,attribute_data','featured_images'])->paginate(2); if ($data){ return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]); diff --git a/plugins/ahmadfatoni/apigenerator/controllers/api/postsController.php b/plugins/ahmadfatoni/apigenerator/controllers/api/postsController.php index 556fa1b..f7f9d31 100644 --- a/plugins/ahmadfatoni/apigenerator/controllers/api/postsController.php +++ b/plugins/ahmadfatoni/apigenerator/controllers/api/postsController.php @@ -7,6 +7,7 @@ use Illuminate\Http\Request; use AhmadFatoni\ApiGenerator\Helpers\Helpers; use Illuminate\Support\Facades\Validator; use RainLab\Blog\Models\Post; +use RainLab\Blog\Models\Category; class postsController extends Controller { protected $Post; @@ -22,9 +23,13 @@ class postsController extends Controller public function index(){ + $input = \Input::all(); + $pgn=$input['pgn']; + // dd($pgn); + // $data = $this->Post->all()->toArray(); - $data = $this->Post::with(['translations:locale,model_id,attribute_data','categories','featured_images'])->paginate(6); + $data = $this->Post::with(['translations:locale,model_id,attribute_data','categories:name','featured_images'])->paginate($pgn); return $this->helpers->apiArrayResponseBuilder(200, 'success', $data); }