Skip to content

Commit 6a8e62a

Browse files
committed
- Added method to override the default query builder
1 parent 4d3a06e commit 6a8e62a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Concerns/IsApiController.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ protected function getPerPage(Request $request, int $default = 0)
6363
return abs($request->input('per_page', $default));
6464
}
6565

66+
protected function getQueryBuilder(): QueryBuilder
67+
{
68+
return QueryBuilder::for($this->getBaseQuery());
69+
}
70+
6671
/**
6772
* Display a listing of the resource.
6873
*
@@ -75,7 +80,7 @@ protected function indexEndpoint(Request $request)
7580

7681
$this->validate($request, $this->getIndexValidation());
7782

78-
$query = QueryBuilder::for($this->getBaseQuery());
83+
$query = $this->getQueryBuilder();
7984

8085
if ($default_sort = $this->getDefaultSort()) {
8186
$query->defaultSort($default_sort);
@@ -111,7 +116,7 @@ protected function showEndpoint($model_id, Request $request)
111116
$this->validate($request, $this->getShowValidation());
112117

113118
try {
114-
$model = QueryBuilder::for($this->getBaseQuery())
119+
$model = $this->getQueryBuilder()
115120
->allowedAppends($this->getAllShowAllowedAppends())
116121
->fieldsToAlwaysInclude($this->getFieldsToAlwaysInclude())
117122
->allowedFields($this->getAllowedFields())

0 commit comments

Comments
 (0)