Reinstated the help button.

This commit is contained in:
James Cole
2015-06-29 15:23:50 +02:00
parent 847e05e9a7
commit 428e331b3e
10 changed files with 793 additions and 578 deletions

View File

@@ -37,6 +37,36 @@ class Budget extends Model
protected $fillable = ['user_id', 'name', 'active'];
protected $hidden = ['encrypted'];
/**
* @param array $fields
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @codeCoverageIgnore
*
* @return Budget
*/
public static function firstOrCreateEncrypted(array $fields)
{
// everything but the name:
$query = Budget::orderBy('id');
foreach ($fields as $name => $value) {
if ($name != 'name') {
$query->where($name, $value);
}
}
$set = $query->get(['budgets.*']);
/** @var Budget $budget */
foreach ($set as $budget) {
if ($budget->name == $fields['name']) {
return $budget;
}
}
// create it!
$budget = Budget::create($fields);
return $budget;
}
/**
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany