update api posts
This commit is contained in:
parent
744e926a39
commit
fa21ac42f3
|
|
@ -7,6 +7,7 @@ use Illuminate\Http\Request;
|
||||||
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use RainLab\Blog\Models\Category;
|
use RainLab\Blog\Models\Category;
|
||||||
|
use RainLab\Blog\Models\Post;
|
||||||
class categoriesController extends Controller
|
class categoriesController extends Controller
|
||||||
{
|
{
|
||||||
protected $Category;
|
protected $Category;
|
||||||
|
|
@ -21,7 +22,7 @@ class categoriesController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(){
|
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->all()->toArray();
|
||||||
$data = $this->Category::with(['translations:locale,model_id,attribute_data','posts.translations'])->get();
|
$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){
|
public function show($id){
|
||||||
// $data = $this->Post::with(['translations:locale,model_id,attribute_data','categories'])->get();
|
// $input = \Input::all();
|
||||||
$data = $this->Category::with(['translations:locale,model_id,attribute_data','posts.featured_images' , 'posts.translations'])->find($id);
|
// $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){
|
if ($data){
|
||||||
return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]);
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', [$data]);
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use Illuminate\Http\Request;
|
||||||
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
use AhmadFatoni\ApiGenerator\Helpers\Helpers;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use RainLab\Blog\Models\Post;
|
use RainLab\Blog\Models\Post;
|
||||||
|
use RainLab\Blog\Models\Category;
|
||||||
class postsController extends Controller
|
class postsController extends Controller
|
||||||
{
|
{
|
||||||
protected $Post;
|
protected $Post;
|
||||||
|
|
@ -22,9 +23,13 @@ class postsController extends Controller
|
||||||
|
|
||||||
public function index(){
|
public function index(){
|
||||||
|
|
||||||
|
$input = \Input::all();
|
||||||
|
$pgn=$input['pgn'];
|
||||||
|
// dd($pgn);
|
||||||
|
|
||||||
// $data = $this->Post->all()->toArray();
|
// $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);
|
return $this->helpers->apiArrayResponseBuilder(200, 'success', $data);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue