. */ declare(strict_types=1); namespace FireflyIII\Http\Requests; use FireflyIII\Models\RuleGroup; use FireflyIII\Rules\IsBoolean; /** * Class RuleGroupFormRequest. */ class RuleGroupFormRequest extends Request { /** * Verify the request. * * @return bool */ public function authorize(): bool { // Only allow logged in users return auth()->check(); } /** * Get all data for controller. * * @return array */ public function getRuleGroupData(): array { $active = true; if (null !== $this->get('active')) { $active = $this->boolean('active'); } return [ 'title' => $this->string('title'), 'description' => $this->nlString('description'), 'active' => $active, ]; } /** * Rules for this request. * * @return array */ public function rules(): array { $titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title'; /** @var RuleGroup $ruleGroup */ $ruleGroup = $this->route()->parameter('ruleGroup'); if (null !== $ruleGroup) { $titleRule = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . $ruleGroup->id; } return [ 'title' => $titleRule, 'description' => 'between:1,5000|nullable', 'active' => [new IsBoolean], ]; } }