'required', 'default' => false, 'rules' => ['required' => 'present|boolean'], 'label' => 'Erforderlich'], ['key' => 'parent_field', 'default' => null, 'rules' => ['parent_field' => 'present|nullable|string'], 'label' => 'Übergeordnetes Feld'], ['key' => 'parent_group', 'default' => null, 'rules' => ['parent_group' => ['present', 'nullable', Rule::in(Group::pluck('id')->toArray())]], 'label' => 'Übergeordnete Gruppierung'], ]; } public static function default(): string { return ''; } public static function fake(Generator $faker): array { return [ 'required' => $faker->boolean(), 'parent_field' => null, 'parent_group' => null, ]; } /** * @inheritdoc */ public function getRegistrationRules(): array { $rules = [$this->required ? 'required' : 'nullable']; $rules[] = 'integer'; if ($this->parentGroup) { $rules[] = Rule::in(Group::find($this->parentGroup)->children()->pluck('id')); } if ($this->parentField && request()->input($this->parentField)) { $rules[] = Rule::in(Group::find(request()->input($this->parentField))->children()->pluck('id')); } return [$this->key => $rules]; } /** * @inheritdoc */ public function getRegistrationAttributes(): array { return [$this->key => $this->name]; } /** * @inheritdoc */ public function getRegistrationMessages(): array { return []; } public function getPresenter(): Presenter { return app(GroupPresenter::class); } }