Layout updates and extensions. Found a problem I need closures for. Yay! [skip ci]

This commit is contained in:
James Cole
2014-07-28 14:53:04 +02:00
parent 2680cd8b7a
commit b0ddc04a0d
17 changed files with 233 additions and 44 deletions

View File

@@ -21,6 +21,12 @@ interface BudgetRepositoryInterface
*/
public function get();
/**
* @param $data
* @return mixed
*/
public function update($data);
/**
* @param $data
*
@@ -28,6 +34,12 @@ interface BudgetRepositoryInterface
*/
public function store($data);
/**
* @param $data
* @return mixed
*/
public function destroy($data);
/**
* @param $budgetId
*

View File

@@ -29,7 +29,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
public function get()
{
$set = \Auth::user()->budgets()->with(
['limits' => function ($q) {
['limits' => function ($q) {
$q->orderBy('limits.startdate', 'ASC');
}, 'limits.limitrepetitions' => function ($q) {
$q->orderBy('limit_repetitions.startdate', 'ASC');
@@ -46,6 +46,31 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
return $set;
}
/**
* @param $data
* @return mixed
*/
public function update($data) {
$budget = $this->find($data['id']);
if ($budget) {
// update account accordingly:
$budget->name = $data['name'];
if ($budget->validate()) {
$budget->save();
}
}
return $budget;
}
public function destroy($budgetId) {
$budget = $this->find($budgetId);
if($budget) {
$budget->delete();
return true;
}
return false;
}
/**
* @return array|mixed
*/
@@ -72,7 +97,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
{
$set = \Auth::user()->budgets()->with(
['limits' => function ($q) use ($date) {
['limits' => function ($q) use ($date) {
$q->orderBy('limits.startdate', 'ASC');
}, 'limits.limitrepetitions' => function ($q) use ($date) {
$q->orderBy('limit_repetitions.startdate', 'ASC');
@@ -156,7 +181,7 @@ class EloquentBudgetRepository implements BudgetRepositoryInterface
$limit->save();
}
}
if($budget->validate()) {
if ($budget->validate()) {
$budget->save();
}
return $budget;