From aa3d120b96e3914e8037cba7223ed0d444e9f8a0 Mon Sep 17 00:00:00 2001 From: Max Date: Mon, 21 Oct 2019 22:20:23 +1100 Subject: [PATCH] Add ability to specify per_page value on getAll request (#21) * Bringing dev up to speed (#19) * Bug fix (#16) * Bug fix Bug fix for: https://github.com/specialtactics/laravel5-api-boilerplate/issues/26 * Update RestfulTransformer.php * Update RestfulTransformer.php StyleCI ?! * Add test for situation where model has a PK of "id" * Add tests for empty attributes cast to array * Some updates for laravel 6 (#18) * Updates for Laravel 6 * Remove PHP 7.1 from Travis (no longer supported) * Bump illuminate/support dep version * Bump orchestra testbench version for laravel 6 * Allow phpunit 8 * Replace str_ helper * replace assertEquals with assertEqualsWithDelta when using delta * Add phpunit result cache to gitignore * Update travis config * Different config try * Cater testing for laravel 5.8 as well * Commit a test to run first and eat up bootstrap time * Add ability to specify per_page value on getAll request * Newline oddity --- src/Http/Controllers/RestfulController.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Http/Controllers/RestfulController.php b/src/Http/Controllers/RestfulController.php index 32b0110..9298dd4 100644 --- a/src/Http/Controllers/RestfulController.php +++ b/src/Http/Controllers/RestfulController.php @@ -26,6 +26,11 @@ public function getAll() // Handle pagination, if applicable $perPage = $model->getPerPage(); if ($perPage) { + // If specified, use per_page of the request + if (request()->has('per_page')) { + $perPage = intval(request()->input('per_page')); + } + $paginator = $query->paginate($perPage); return $this->response->paginator($paginator, $this->getTransformer());