. */ declare(strict_types=1); namespace FireflyIII\Api\V1\Requests; use FireflyIII\Models\RuleGroup; use FireflyIII\Rules\IsBoolean; /** * @codeCoverageIgnore * Class RuleGroupRequest * TODO AFTER 4.8,0: split this into two request classes. */ class RuleGroupRequest extends Request { /** * Authorize logged in users. * * @return bool */ public function authorize(): bool { // Only allow authenticated users return auth()->check(); } /** * Get all data from the request. * * @return array */ public function getAll(): array { $active = true; if (null !== $this->get('active')) { $active = $this->boolean('active'); } return [ 'title' => $this->string('title'), 'description' => $this->string('description'), 'active' => $active, ]; } /** * The rules that the incoming request must be matched against. * * @return array */ public function rules(): array { $rules = [ 'title' => 'required|between:1,100|uniqueObjectForUser:rule_groups,title', 'description' => 'between:1,5000|nullable', 'active' => [new IsBoolean], ]; switch ($this->method()) { default: break; case 'PUT': case 'PATCH': /** @var RuleGroup $ruleGroup */ $ruleGroup = $this->route()->parameter('ruleGroup'); $rules['title'] = 'required|between:1,100|uniqueObjectForUser:rule_groups,title,' . $ruleGroup->id; break; } return $rules; } }