Skip to content

Commit

Permalink
Extract method to retrieve searchable attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevebauman committed Oct 10, 2024
1 parent 83a0fd3 commit 34e4bbc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ public function where(array|string $attribute, mixed $value = null): self
{
$wheres = is_string($attribute) ? [$attribute => $value] : $attribute;

$searchable = [
$this->model->getKeyName(),
...$this->model->getSearchable(),
];
$searchable = $this->getSearchableAttributes();

foreach ($wheres as $key => $value) {
if (! in_array($key, $searchable)) {
Expand All @@ -115,6 +112,17 @@ public function where(array|string $attribute, mixed $value = null): self
return $this;
}

/**
* Get the searchable attributes for the model.
*/
protected function getSearchableAttributes(): array
{
return [
$this->model->getKeyName(),
...$this->model->getSearchable(),
];
}

/**
* Prepare a value for a where clause.
*/
Expand Down

0 comments on commit 34e4bbc

Please sign in to comment.