3 namespace BookStack\Http;
5 use BookStack\Api\ListingResponseBuilder;
6 use Illuminate\Database\Eloquent\Builder;
7 use Illuminate\Http\JsonResponse;
9 abstract class ApiController extends Controller
12 * The validation rules for this controller.
13 * Can alternative be defined in a rules() method is they need to be dynamic.
15 * @var array<string, array<string, string[]>>
17 protected array $rules = [];
20 * Provide a paginated listing JSON response in a standard format
21 * taking into account any pagination parameters passed by the user.
23 protected function apiListingResponse(Builder $query, array $fields, array $modifiers = []): JsonResponse
25 $listing = new ListingResponseBuilder($query, request(), $fields);
27 foreach ($modifiers as $modifier) {
28 $listing->modifyResults($modifier);
31 return $listing->toResponse();
35 * Get the validation rules for this controller.
36 * Defaults to a $rules property but can be a rules() method.
38 public function getValidationRules(): array
40 return $this->rules();
44 * Get the validation rules for the actions in this controller.
45 * Defaults to a $rules property but can be a rules() method.
47 protected function rules(): array