Skip to content

Commit

Permalink
Add default values for all config values
Browse files Browse the repository at this point in the history
This is usefull when QueryBuilder is used as a dependency in another
package (without its default config includes).

See #889
  • Loading branch information
AlexVanderbist committed Sep 12, 2023
1 parent 178570f commit 2364b28
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/AllowedInclude.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public static function relationship(string $name, ?string $internalName = null):
]);

if (! Str::contains($relationship, '.')) {
$countSuffix = config('query-builder.count_suffix');
$existsSuffix = config('query-builder.exists_suffix');
$countSuffix = config('query-builder.count_suffix', 'Count');
$existsSuffix = config('query-builder.exists_suffix', 'Exists');

$includes = $includes
->merge(self::count(
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/AddsIncludesToQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ public function allowedIncludes($includes): static
return collect([$include]);
}

if (Str::endsWith($include, config('query-builder.count_suffix'))) {
if (Str::endsWith($include, config('query-builder.count_suffix', 'Count'))) {
return AllowedInclude::count($include);
}

if (Str::endsWith($include, config('query-builder.exists_suffix'))) {
if (Str::endsWith($include, config('query-builder.exists_suffix', 'Exists'))) {
return AllowedInclude::exists($include);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/FiltersQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function isFilterRequested(AllowedFilter $allowedFilter): bool

protected function ensureAllFiltersExist()
{
if (config('query-builder.disable_invalid_filter_query_exception')) {
if (config('query-builder.disable_invalid_filter_query_exception', false)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/SortsQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ protected function findSort(string $property): ?AllowedSort

protected function ensureAllSortsExist(): void
{
if (config('query-builder.disable_invalid_sort_query_exception')) {
if (config('query-builder.disable_invalid_sort_query_exception', false)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Includes/IncludedCount.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ class IncludedCount implements IncludeInterface
{
public function __invoke(Builder $query, string $count)
{
$query->withCount(Str::before($count, config('query-builder.count_suffix')));
$query->withCount(Str::before($count, config('query-builder.count_suffix', 'Count')));
}
}
2 changes: 1 addition & 1 deletion src/Includes/IncludedExists.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class IncludedExists implements IncludeInterface
{
public function __invoke(Builder $query, string $exists)
{
$exists = Str::before($exists, config('query-builder.exists_suffix'));
$exists = Str::before($exists, config('query-builder.exists_suffix', 'Exists'));

$query
->withExists($exists)
Expand Down
10 changes: 5 additions & 5 deletions src/QueryBuilderRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function fromRequest(Request $request): self

public function includes(): Collection
{
$includeParameterName = config('query-builder.parameters.include');
$includeParameterName = config('query-builder.parameters.include', 'include');

$includeParts = $this->getRequestData($includeParameterName);

Expand All @@ -47,7 +47,7 @@ public function includes(): Collection

public function appends(): Collection
{
$appendParameterName = config('query-builder.parameters.append');
$appendParameterName = config('query-builder.parameters.append', 'append');

$appendParts = $this->getRequestData($appendParameterName);

Expand All @@ -60,7 +60,7 @@ public function appends(): Collection

public function fields(): Collection
{
$fieldsParameterName = config('query-builder.parameters.fields');
$fieldsParameterName = config('query-builder.parameters.fields', 'fields');
$fieldsData = $this->getRequestData($fieldsParameterName);

$fieldsPerTable = collect(is_string($fieldsData) ? explode(static::getFieldsArrayValueDelimiter(), $fieldsData) : $fieldsData);
Expand Down Expand Up @@ -95,7 +95,7 @@ public function fields(): Collection

public function sorts(): Collection
{
$sortParameterName = config('query-builder.parameters.sort');
$sortParameterName = config('query-builder.parameters.sort', 'sort');

$sortParts = $this->getRequestData($sortParameterName);

Expand All @@ -108,7 +108,7 @@ public function sorts(): Collection

public function filters(): Collection
{
$filterParameterName = config('query-builder.parameters.filter');
$filterParameterName = config('query-builder.parameters.filter', 'filter');

$filterParts = $this->getRequestData($filterParameterName, []);

Expand Down

1 comment on commit 2364b28

@jbrooksuk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Please sign in to comment.