So I am creating a Laravel API with version 5.1. I am using Repositories. I am very accomplished at creating Laravel apps WITHOUT using repositories and due to the suggestions I found online decided to give it a try. My current issue is finding a valid and not ridiculously complicated way to sort and filter when an API request calls for it.
I have found a few sites that have pointed me in directions but in the end I can't really get a grip on it. For example, I have a Contributions controller and I am trying to create an index method that allows for pagination / sorting / filtering.
ContributionsController@index:
public function index(Request $request, ContributionInterface $contributionRepo)
{
if (config('cache.cache_results')) {
$contributions = Cache::tags(['contributions'])->remember("contributions.index", 60, function() use ($memberId, $contributionRepo){
return $contributionRepo->paginate();
});
} else {
$contributions = $contributionRepo->paginate();
}
$transformedData = $this->fractal->paginatedCollection($contributions, new ContributionTransformer());
return $this->sendResponse($transformedData['data'], $transformedData['meta']);
}
This will get me a paginated index of contributions....no big deal...but now I need to be able to accept user-defined sorting and filtering and am clueless how to do it using repositories. No they cannot sort and filter on the front end because im only returning 15 items and pagination meta data. This is necessary because were currently sitting just short of 1 million contribution entries so sending them everything obviously wouldn't work. Any ideas / suggestions would be great.