Skip to content

Firefly III: a personal finances manager

Fixed unique piggy check.

James Coleb9000519e46c
diff --git a/app/Http/Requests/PiggyBankFormRequest.php b/app/Http/Requests/PiggyBankFormRequest.php
index b794ba6871..768eda19a4 100644
--- a/app/Http/Requests/PiggyBankFormRequest.php
+++ b/app/Http/Requests/PiggyBankFormRequest.php
@@ -30,7 +30,7 @@ class PiggyBankFormRequest extends Request
public function rules()
{
- $nameRule = 'required|between:1,255|uniqueForUser:piggy_banks,name';
+ $nameRule = 'required|between:1,255|uniquePiggyBankForUser:piggy_banks,name';
$targetDateRule = 'date';
if (intval(Input::get('id'))) {
$nameRule = 'required|between:1,255';
diff --git a/app/Validation/FireflyValidator.php b/app/Validation/FireflyValidator.php
index c2f4087517..d4b4771e90 100644
--- a/app/Validation/FireflyValidator.php
+++ b/app/Validation/FireflyValidator.php
@@ -83,16 +83,16 @@ class FireflyValidator extends Validator
$validTypes = array_keys(Config::get('firefly.subTitlesByIdentifier'));
- $type = isset($this->data['what']) && in_array($this->data['what'],$validTypes) ? $this->data['what'] : null;
+ $type = isset($this->data['what']) && in_array($this->data['what'], $validTypes) ? $this->data['what'] : null;
// some fallback:
- if(is_null($type)) {
- $type = in_array(Input::get('what'),$validTypes) ? Input::get('what') : null;
+ if (is_null($type)) {
+ $type = in_array(Input::get('what'), $validTypes) ? Input::get('what') : null;
}
// still null?
- if(is_null($type)) {
+ if (is_null($type)) {
// find by other field:
- $type = isset($this->data['account_type_id']) ? $this->data['account_type_id'] : 0;
- $dbType = AccountType::find($type);
+ $type = isset($this->data['account_type_id']) ? $this->data['account_type_id'] : 0;
+ $dbType = AccountType::find($type);
} else {
$longType = Config::get('firefly.accountTypeByIdentifier.' . $type);
$dbType = AccountType::whereType($longType)->first();
@@ -142,5 +142,29 @@ class FireflyValidator extends Validator
return false;
}
+
+ /**
+ * @param $attribute
+ * @param $value
+ * @param $parameters
+ *
+ * @return bool
+ */
+ public function validateUniquePiggyBankForUser($attribute, $value, $parameters)
+ {
+ $query = DB::table($parameters[0])->where('piggy_banks.'.$parameters[1], $value);
+ $query->leftJoin('accounts', 'accounts.id', '=', 'piggy_banks.account_id');
+ $query->where('accounts.user_id', Auth::user()->id);
+ if (isset($paramers[2])) {
+ $query->where('piggy_banks.id', '!=', $parameters[2]);
+ }
+ $count = $query->count();
+ if ($count == 0) {
+ return true;
+ }
+
+ return false;
+
+ }
}