Unverified Commit 3b32762f authored by Nicolas Widart's avatar Nicolas Widart Committed by GitHub

Merge pull request #639 from xfudox/master

added where() and with() to EloquentBaseRepository
parents 24d1aeb2 caaafd92
......@@ -98,4 +98,20 @@ interface BaseRepository
* @return bool
*/
public function clearCache();
/**
* Add where statement to current builder
*
* @param string $field
* @param string|int $value
* @param string $operator
*/
public function where(string $field, $value, string $operator = null);
/**
* Eager relationship(s) loading
*
* @param array|string $relationships
*/
public function with($relationships);
}
......@@ -220,4 +220,24 @@ abstract class BaseCacheDecorator implements BaseRepository
$this->entityName
);
}
/**
* @inheritdoc
*/
public function where(string $field, $value, string $operator = null)
{
return $this->remember(function () use ($field, $value, $operator) {
return $this->repository->where($field, $value, $operator);
});
}
/**
* @inheritdoc
*/
public function with($relationships)
{
return $this->remember(function () use ($relationships) {
return $this->repository->with($relationships);
});
}
}
......@@ -191,4 +191,26 @@ abstract class EloquentBaseRepository implements BaseRepository
{
return true;
}
/**
* @inheritdoc
*/
public function where(string $field, $value, string $operator = null)
{
if ($operator === null) {
$operator = '=';
} else {
list($value, $operator) = [$operator, $value];
}
return $this->model->where($field, $operator, $value);
}
/**
* @inheritdoc
*/
public function with($relationships)
{
return $this->model->with($relationships);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment