Skip to content

Commit

Permalink
Improved repository
Browse files Browse the repository at this point in the history
  • Loading branch information
libern committed Jul 25, 2016
1 parent 26b2cb4 commit 98e8589
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/Someline/Base/Repositories/Eloquent/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,52 @@ public function getIsSearchableForceAndWhere()
return $this->isSearchableForceAndWhere;
}

/**
* Find data by where conditions
*
* @param array $where
*
* @return $this
*/
public function where(array $where)
{
$this->applyCriteria();
$this->applyScope();

$this->applyConditions($where);

return $this;
}

/**
* Retrieve first data of repository with fail if not found
*
* @param array $columns
*
* @return mixed
*/
public function firstOrFail($columns = ['*'])
{
$this->applyCriteria();
$this->applyScope();

$results = $this->model->firstOrFail($columns);

$this->resetModel();

return $this->parserResult($results);
}

/**
* Where first
*
* @param array $where
* @param array $columns
* @return mixed
*/
public function whereFirst(array $where, $columns = ['*'])
{
return $this->where($where)->firstOrFail($columns = ['*']);
}

}
27 changes: 27 additions & 0 deletions src/Someline/Base/Repositories/Interfaces/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,31 @@ public function setPresenterMeta(array $meta);
*/
public function getIsSearchableForceAndWhere();

/**
* Find data by where conditions
*
* @param array $where
*
* @return $this
*/
public function where(array $where);

/**
* Retrieve first data of repository with fail if not found
*
* @param array $columns
*
* @return mixed
*/
public function firstOrFail($columns = ['*']);

/**
* Where first
*
* @param array $where
* @param array $columns
* @return mixed
*/
public function whereFirst(array $where, $columns = ['*']);

}

0 comments on commit 98e8589

Please sign in to comment.