3 namespace BookStack\Http\Controllers\Api;
5 use BookStack\Api\ListingResponseBuilder;
6 use BookStack\Http\Controllers\Controller;
7 use Illuminate\Database\Eloquent\Builder;
8 use Illuminate\Http\JsonResponse;
10 abstract class ApiController extends Controller
12 protected $rules = [];
15 * Provide a paginated listing JSON response in a standard format
16 * taking into account any pagination parameters passed by the user.
18 protected function apiListingResponse(Builder $query, array $fields, array $modifiers = []): JsonResponse
20 $listing = new ListingResponseBuilder($query, request(), $fields);
22 foreach ($modifiers as $modifier) {
23 $listing->modifyResults($modifier);
26 return $listing->toResponse();
30 * Get the validation rules for this controller.
31 * Defaults to a $rules property but can be a rules() method.
33 public function getValidationRules(): array
35 return $this->rules();
39 * Get the validation rules for the actions in this controller.
40 * Defaults to a $rules property but can be a rules() method.
42 protected function rules(): array