]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/Api/ApiController.php
Added force option for update-url command
[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, array $modifiers = []): JsonResponse
19     {
20         $listing = new ListingResponseBuilder($query, request(), $fields);
21
22         foreach ($modifiers as $modifier) {
23             $listing->modifyResults($modifier);
24         }
25
26         return $listing->toResponse();
27     }
28
29     /**
30      * Get the validation rules for this controller.
31      * Defaults to a $rules property but can be a rules() method.
32      */
33     public function getValidationRules(): array
34     {
35         return $this->rules();
36     }
37
38     /**
39      * Get the validation rules for the actions in this controller.
40      * Defaults to a $rules property but can be a rules() method.
41      */
42     protected function rules(): array
43     {
44         return $this->rules;
45     }
46 }