Skip to content

Commit

Permalink
Now updateOrCreateBy() always returns a model
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleangioni committed Dec 28, 2015
1 parent 08a9eb7 commit 37dcf79
Showing 1 changed file with 2 additions and 18 deletions.
20 changes: 2 additions & 18 deletions src/MicheleAngioni/Support/Repos/AbstractEloquentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,27 @@ public function find($id, array $with = array())
return $query->find($id);
}


public function findOrFail($id, array $with = array())
{
$query = $this->make($with);

return $query->findOrFail($id);
}


public function first()
{
$query = $this->make();

return $query->first();
}


public function firstOrFail()
{
$query = $this->make();

return $query->firstOrFail();
}


public function firstBy(array $where = array(), array $with = array())
{
$query = $this->make($with);
Expand All @@ -69,7 +65,6 @@ public function firstBy(array $where = array(), array $with = array())
return $query->first();
}


public function firstOrFailBy(array $where = array(), array $with = array())
{
$query = $this->make($with);
Expand All @@ -81,7 +76,6 @@ public function firstOrFailBy(array $where = array(), array $with = array())
return $query->firstOrFail();
}


public function getBy(array $where = array(), array $with = array())
{
$query = $this->make($with);
Expand All @@ -93,7 +87,6 @@ public function getBy(array $where = array(), array $with = array())
return $query->get();
}


public function getByLimit($limit, array $where = array(), array $with = array())
{
$query = $this->make($with);
Expand All @@ -105,7 +98,6 @@ public function getByLimit($limit, array $where = array(), array $with = array()
return $query->take($limit)->get();
}


public function getByOrder($orderBy, array $where = array(), array $with = array(), $order = 'desc', $limit = 0)
{
$query = $this->make($with);
Expand All @@ -123,7 +115,6 @@ public function getByOrder($orderBy, array $where = array(), array $with = array
return $query->get();
}


public function getIn($whereInKey, array $whereIn = array(), $with = array(), $orderBy = NULL, $order = 'desc', $limit = 0)
{
$query = $this->make($with);
Expand Down Expand Up @@ -308,23 +299,20 @@ public function insert(array $collection)
return $this->model->insert($collection);
}


public function create(array $inputs = [])
{
$inputs = $this->purifyInputs($inputs);

return $this->model->create($inputs);
}


public function update(array $inputs)
{
$inputs = $this->purifyInputs($inputs);

return $this->model->update($inputs);
}


public function updateById($id, array $inputs)
{
$inputs = $this->purifyInputs($inputs);
Expand All @@ -334,7 +322,6 @@ public function updateById($id, array $inputs)
return $model->update($inputs);
}


public function updateBy(array $where, array $inputs)
{
$inputs = $this->purifyInputs($inputs);
Expand All @@ -348,7 +335,6 @@ public function updateBy(array $where, array $inputs)
return $query->update($inputs);
}


public function updateOrCreateBy(array $where, array $inputs = [])
{
$inputs = $this->purifyInputs($inputs);
Expand All @@ -363,20 +349,20 @@ public function updateOrCreateBy(array $where, array $inputs = [])

if($model) {
$model->update($inputs);

return $model;
}
else {
return $this->model->create($inputs);
}
}


public function destroy($id)
{
$model = $this->model->findOrFail($id);
return $model->delete();
}


public function destroyFirstBy(array $where)
{
$where = $this->purifyInputs($where);
Expand All @@ -385,7 +371,6 @@ public function destroyFirstBy(array $where)
return $model->delete();
}


public function truncate()
{
return $this->model->truncate();
Expand All @@ -400,7 +385,6 @@ public function count()
return $this->model->count();
}


public function countBy(array $where = array())
{
$query = $this->make();
Expand Down

0 comments on commit 37dcf79

Please sign in to comment.