Skip to content

Commit

Permalink
Add filter preparation
Browse files Browse the repository at this point in the history
  • Loading branch information
sidigi committed Oct 15, 2020
1 parent 07aad3d commit 209fc99
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/Traits/HasFilterField.php
Expand Up @@ -9,16 +9,19 @@ trait HasFilterField
protected string $filterField = 'filter';
protected $defaultRules = ['nullable', 'array'];

protected function prepareForValidation() : void
{
$this->prepareFiltersForValidation();
}

public function filterKey() : string
{
return $this->filterField;
}

public function filters(string $key = null)
{
$filters = $this->strToArray(
$this->{$this->filterKey()}
);
$filters = $this->{$this->filterKey()};

if ($key) {
return $filters[$key] ?? null;
Expand All @@ -41,6 +44,19 @@ protected function filterRules() : array
);
}

protected function prepareFiltersForValidation() : void
{
$filters = $this->{$this->filterKey()};

if (! is_array($filters)) {
return;
}

$this->merge([
$this->filterKey() => $this->strToArray($filters),
]);
}

protected function eachValueFilterRules() : array
{
return [];
Expand Down

0 comments on commit 209fc99

Please sign in to comment.