Skip to content

Commit f05c8e4

Browse files
committed
Added "exists" method
1 parent 870e01c commit f05c8e4

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/Contracts/RepositoryContract.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ public function findWhereNotIn($attribute, array $values, $columns = ['*']);
113113
*/
114114
public function count();
115115

116+
/**
117+
* Determine if the entity exists.
118+
*
119+
* @return mixed
120+
*/
121+
public function exists();
122+
116123
/**
117124
* Create new entity.
118125
*

src/Eloquent/BaseRepository.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,24 @@ public function count()
313313
return $count;
314314
}
315315

316+
/**
317+
* Determine if the entity exists.
318+
*
319+
* @return mixed
320+
*/
321+
public function exists()
322+
{
323+
$this->applyCriteria();
324+
$this->applyScope();
325+
326+
$exists = $this->query->exists();
327+
328+
$this->resetScope();
329+
$this->resetQuery();
330+
331+
return $exists;
332+
}
333+
316334
/**
317335
* Create new entity.
318336
*

0 commit comments

Comments
 (0)