Skip to content

Commit

Permalink
fix: return false on no result
Browse files Browse the repository at this point in the history
  • Loading branch information
ipranjal committed Sep 30, 2024
1 parent 81f2153 commit f64018f
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,27 @@ public function from($table, $alias = null): QueryBuilder
return parent::from($table,$alias);
}

public function get(): Collection
public function get(): Collection|bool
{
$model = $this->modelManager->create($this->table);
$relations = $this->relations;
$this->relations = [];
return Collection::fromIterable($this->fetchAllAssociative())
$results = $this->fetchAllAssociative();
if (empty($results)) {
return false;
}
return Collection::fromIterable($results)
->map(static fn($value): Model => ($model)->setProperties($value)->with($relations)->setLoaded());
}

public function first(): Model
public function first(): Model|bool
{
$relations = $this->relations;
$this->relations = [];
$result = $this->fetchAssociative() ? $this->fetchAssociative() : [];
if (empty($result)) {
return false;
}
return ($this->modelManager->create($this->table))->setProperties($result)->with($relations)->setLoaded();
}
}

0 comments on commit f64018f

Please sign in to comment.