update api posts

This commit is contained in:
gerchek 2022-01-20 22:00:49 +05:00
parent 744e926a39
commit fa21ac42f3
2 changed files with 18 additions and 4 deletions

View File

@ -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]);

View File

@ -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);
}