diff --git a/app/Http/Requests/PiggyBankStoreRequest.php b/app/Http/Requests/PiggyBankStoreRequest.php new file mode 100644 index 0000000000..89af1191ee --- /dev/null +++ b/app/Http/Requests/PiggyBankStoreRequest.php @@ -0,0 +1,76 @@ +. + */ +declare(strict_types=1); + +namespace FireflyIII\Http\Requests; + +/** + * Class PiggyBankStoreRequest. + */ +class PiggyBankStoreRequest extends Request +{ + /** + * Verify the request. + * + * @return bool + */ + public function authorize(): bool + { + // Only allow logged in users + return auth()->check(); + } + + /** + * Returns the data required by the controller. + * + * @return array + */ + public function getPiggyBankData(): array + { + return [ + 'name' => $this->string('name'), + 'startdate' => $this->date('startdate'), + 'account_id' => $this->integer('account_id'), + 'targetamount' => $this->string('targetamount'), + 'targetdate' => $this->date('targetdate'), + 'notes' => $this->nlString('notes'), + 'object_group' => $this->string('object_group'), + ]; + } + + /** + * Rules for this request. + * + * @return array + */ + public function rules(): array + { + return [ + 'name' => 'required|between:1,255|uniquePiggyBankForUser', + 'account_id' => 'required|belongsToUser:accounts', + 'targetamount' => 'required|numeric|gte:0.01|max:1000000000', + 'startdate' => 'date', + 'targetdate' => 'date|nullable', + 'order' => 'integer|min:1', + 'object_group' => 'min:0|max:255', + ]; + } +} diff --git a/app/Http/Requests/PiggyBankFormRequest.php b/app/Http/Requests/PiggyBankUpdateRequest.php similarity index 86% rename from app/Http/Requests/PiggyBankFormRequest.php rename to app/Http/Requests/PiggyBankUpdateRequest.php index afe336b96b..c3dc8e9be0 100644 --- a/app/Http/Requests/PiggyBankFormRequest.php +++ b/app/Http/Requests/PiggyBankUpdateRequest.php @@ -1,6 +1,6 @@ route()->parameter('piggyBank'); - if (null !== $piggy) { - $nameRule = 'required|between:1,255|uniquePiggyBankForUser:' . $piggy->id; - } - - $rules = [ - 'name' => $nameRule, + return [ + 'name' => sprintf('required|between:1,255|uniquePiggyBankForUser:%d', $piggy->id), 'account_id' => 'required|belongsToUser:accounts', 'targetamount' => 'required|numeric|gte:0.01|max:1000000000', 'startdate' => 'date', 'targetdate' => 'date|nullable', 'order' => 'integer|min:1', + 'object_group' => 'min:0|max:255', ]; - - return $rules; } }