Skip to content

Commit

Permalink
improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mahmoudmohamedramadan committed Oct 12, 2024
1 parent 0df8346 commit 53c14ea
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,8 @@ protected function getEloquentBuilder($givenQuery = null)
if (empty($this->getRelationship())) {
$this->eloquentBuilder = $this->getModel()->query()->setQuery($this->queryBuilder);
} else {
// When the relationship is provided, we will start a new query and set the model
// with the given relationship using "getRelated" method on it.
$this->eloquentBuilder = new EloquentBuilder($this->queryBuilder);
$this->eloquentBuilder->setModel($this->getModel()->{$this->getRelationship()}()->getRelated());
}
Expand All @@ -269,6 +271,8 @@ protected function getEloquentBuilder($givenQuery = null)

$this->guessModel();

// There is no ability to search when providing a relationship
// and the model is anonymous (e.g., User::class, new User).
if (!empty($this->getRelationship()) && !$this->getModel()->exists) {
throw new InvalidSearchableModel('Cannot search in a relationship with anonymous model.');
}
Expand Down

0 comments on commit 53c14ea

Please sign in to comment.