mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2024-12-28 09:51:21 -06:00
Fixed unique piggy check.
This commit is contained in:
parent
2694297466
commit
b9000519e4
@ -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';
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user