]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Api/ApiController.php
Applied latest styleci changes
[bookstack] / app / Http / Controllers / Api / ApiController.php
1 <?php
2
3 namespace BookStack\Http\Controllers\Api;
4
5 use BookStack\Api\ListingResponseBuilder;
6 use BookStack\Http\Controllers\Controller;
7 use Illuminate\Database\Eloquent\Builder;
8 use Illuminate\Http\JsonResponse;
9
10 abstract class ApiController extends Controller
11 {
12     protected $rules = [];
13
14     /**
15      * Provide a paginated listing JSON response in a standard format
16      * taking into account any pagination parameters passed by the user.
17      */
18     protected function apiListingResponse(Builder $query, array $fields): JsonResponse
19     {
20         $listing = new ListingResponseBuilder($query, request(), $fields);
21
22         return $listing->toResponse();
23     }
24
25     /**
26      * Get the validation rules for this controller.
27      * Defaults to a $rules property but can be a rules() method.
28      */
29     public function getValdationRules(): array
30     {
31         if (method_exists($this, 'rules')) {
32             return $this->rules();
33         }
34
35         return $this->rules;
36     }
37 }