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 Illuminate\Support\Facades\Validator;
|
||||
use RainLab\Blog\Models\Category;
|
||||
use RainLab\Blog\Models\Post;
|
||||
class categoriesController extends Controller
|
||||
{
|
||||
protected $Category;
|
||||
|
|
@ -29,8 +30,16 @@ class categoriesController extends Controller
|
|||
}
|
||||
|
||||
public function show($id){
|
||||
// $input = \Input::all();
|
||||
// $pgn=$input['pgn'];
|
||||
// $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);
|
||||
$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]);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue