Skip to content

Commit

Permalink
Add count method
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Apr 30, 2024
1 parent ae0b251 commit a6927b1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,11 @@ public function sole($columns = ['*'])
return $result->first();
}

public function exists()
{
return $this->count() >= 1;
}

public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
$page = $page ?: Paginator::resolveCurrentPage($pageName);
Expand Down
5 changes: 5 additions & 0 deletions src/Query/EloquentQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public function sole($columns = ['*'])
return $result->first();
}

public function exists()
{
return $this->builder->count() >= 1;
}

public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
$paginator = $this->builder->paginate($perPage, $this->selectableColumns($columns), $pageName, $page);
Expand Down

0 comments on commit a6927b1

Please sign in to comment.