Commit c7999c03 authored by Viral Solani's avatar Viral Solani

Add filter and sortby support for all APIs

parent b6a5a0de
......@@ -31,10 +31,12 @@ class BlogCategoriesController extends APIController
*/
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$orderBy = $request->get('orderBy') ? $request->get('orderBy') : 'ASC';
$sortBy = $request->get('sortBy') ? $request->get('sortBy') : 'created_at';
return BlogCategoriesResource::collection(
$this->repository->getForDataTable()->paginate($limit)
$this->repository->getForDataTable()->orderBy($sortBy, $orderBy)->paginate($limit)
);
}
......
......@@ -30,9 +30,11 @@ class BlogTagsController extends APIController
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$orderBy = $request->get('orderBy') ? $request->get('orderBy') : 'ASC';
$sortBy = $request->get('sortBy') ? $request->get('sortBy') : 'created_at';
return BlogTagsResource::collection(
$this->repository->getForDataTable()->paginate($limit)
$this->repository->getForDataTable()->orderBy($sortBy, $orderBy)->paginate($limit)
);
}
......
......@@ -30,9 +30,11 @@ class BlogsController extends APIController
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$orderBy = $request->get('orderBy') ? $request->get('orderBy') : 'ASC';
$sortBy = $request->get('sortBy') ? $request->get('sortBy') : 'created_at';
return BlogsResource::collection(
$this->repository->getForDataTable()->paginate($limit)
$this->repository->getForDataTable()->orderBy($sortBy, $orderBy)->paginate($limit)
);
}
......
......@@ -29,10 +29,12 @@ class DeactivatedUsersController extends APIController
*/
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$orderBy = $request->get('orderBy') ? $request->get('orderBy') : 'ASC';
$sortBy = $request->get('sortBy') ? $request->get('sortBy') : 'created_at';
return UserResource::collection(
$this->repository->getForDataTable(0, false)->paginate($limit)
$this->repository->getForDataTable(0, false)->orderBy($sortBy, $orderBy)->paginate($limit)
);
}
}
......@@ -29,10 +29,12 @@ class DeletedUsersController extends APIController
*/
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$orderBy = $request->get('orderBy') ? $request->get('orderBy') : 'ASC';
$sortBy = $request->get('sortBy') ? $request->get('sortBy') : 'created_at';
return UserResource::collection(
$this->repository->getForDataTable(0, true)->paginate($limit)
$this->repository->getForDataTable(0, true)->orderBy($sortBy, $orderBy)->paginate($limit)
);
}
}
......@@ -29,10 +29,12 @@ class FaqsController extends APIController
*/
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$orderBy = $request->get('orderBy') ? $request->get('orderBy') : 'ASC';
$sortBy = $request->get('sortBy') ? $request->get('sortBy') : 'created_at';
return FaqsResource::collection(
$this->repository->getForDataTable()->paginate($limit)
$this->repository->getForDataTable()->orderBy($sortBy, $orderBy)->paginate($limit)
);
}
......
......@@ -29,10 +29,12 @@ class PagesController extends APIController
*/
public function index(Request $request)
{
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$limit = $request->get('paginate') ? $request->get('paginate') : 25;
$orderBy = $request->get('orderBy') ? $request->get('orderBy') : 'ASC';
$sortBy = $request->get('sortBy') ? $request->get('sortBy') : 'created_at';
return PagesResource::collection(
$this->repository->getForDataTable()->paginate($limit)
$this->repository->getForDataTable()->orderBy($sortBy, $orderBy)->paginate($limit)
);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment