Skip to content

Commit

Permalink
✨(repository): 新增判断记录是否存在
Browse files Browse the repository at this point in the history
  • Loading branch information
Joycezhangw committed Feb 7, 2023
1 parent 856b8ed commit b005571
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Repositories/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,11 @@ public function findWhereNotIn(string $field, array $values, $columns = ['*'])
/**
* 判断数据是否存在,存在返回true 不存在返回false
* @param array $where 查询条件
* @return boolean true | false
* @return bool
* @throws RepositoryException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function existsWhere(array $where)
public function existsWhere(array $where): bool
{
$this->applyConditions($where);
$model = $this->model->exists();
Expand All @@ -208,11 +208,11 @@ public function existsWhere(array $where)
/**
* 判断数据是否存在,存在返回 false 不存在返回 true
* @param array $where
* @return mixed
* @return bool
* @throws RepositoryException
* @throws \Illuminate\Contracts\Container\BindingResolutionException
*/
public function doesntExistWhere(array $where)
public function doesntExistWhere(array $where): bool
{
$this->applyConditions($where);
$model = $this->model->doesntExist();
Expand Down
14 changes: 14 additions & 0 deletions src/Repositories/Interfaces/BaseInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ public function findWhereIn(string $field, array $values, $columns = ['*']);
*/
public function findWhereNotIn(string $field, array $values, $columns = ['*']);

/**
* 判断数据是否存在,存在返回true 不存在返回false
* @param array $where 查询条件
* @return bool
*/
public function existsWhere(array $where): bool;

/**
* 判断数据是否存在,存在返回 false 不存在返回 true
* @param array $where
* @return bool
*/
public function doesntExistWhere(array $where): bool;

/**
* 根据主键id获取单条数据
* @param int $id 主键id
Expand Down

0 comments on commit b005571

Please sign in to comment.