. */ declare(strict_types=1); namespace FireflyIII\Http\Requests; use FireflyIII\Models\RuleGroup; use FireflyIII\Rules\IsBoolean; use FireflyIII\Support\Request\ChecksLogin; use FireflyIII\Support\Request\ConvertsDataTypes; use Illuminate\Foundation\Http\FormRequest; /** * Class RuleGroupFormRequest. */ class RuleGroupFormRequest extends FormRequest { use ConvertsDataTypes; use ChecksLogin; /** * 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->convertString('title'), 'description' => $this->stringWithNewlines('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()], ]; } }