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