From 55cd927f12373a2b76cbc34dd067c31d7c4baad3 Mon Sep 17 00:00:00 2001 From: Leonid Nikitin Date: Fri, 7 Jul 2023 00:05:38 +0600 Subject: [PATCH] This commit adds two new components for handling form inputs in the private section of the site. 'Form.php' provides a base class for forms with methods for retrieving request names. 'Input.php' extends this to handle input fields specifically, allowing title, name, type, and value to be specified. An associated Blade view 'input.blade.php' has been added to render these inputs in views. This helps in reusability and maintainability. --- app/View/Components/Private/Forms/Form.php | 32 ++++++++++++ app/View/Components/Private/Forms/Input.php | 50 +++++++++++++++++++ .../private/components/forms/input.blade.php | 7 +++ 3 files changed, 89 insertions(+) create mode 100644 app/View/Components/Private/Forms/Form.php create mode 100644 app/View/Components/Private/Forms/Input.php create mode 100644 resources/views/private/components/forms/input.blade.php diff --git a/app/View/Components/Private/Forms/Form.php b/app/View/Components/Private/Forms/Form.php new file mode 100644 index 0000000..f4fd689 --- /dev/null +++ b/app/View/Components/Private/Forms/Form.php @@ -0,0 +1,32 @@ +requestName)) { + return $this->requestName; + } + + $this->requestName = Str::of($this->getName()) + ->replace( + ['.', '[', ']'], + ['_', '.', ''], + ) + ->rtrim('.') + ->value(); + + return $this->requestName; + } +} diff --git a/app/View/Components/Private/Forms/Input.php b/app/View/Components/Private/Forms/Input.php new file mode 100644 index 0000000..2e3c0af --- /dev/null +++ b/app/View/Components/Private/Forms/Input.php @@ -0,0 +1,50 @@ +name; + } + + protected function getTitle(): string + { + return Str::ucfirst($this->title); + } + + protected function getType(): string + { + return $this->type; + } + + protected function getValue(): string + { + return (string) old($this->getRequestName(), $this->value); + } + + /** + * @inheritDoc + */ + public function render(): View + { + return view('private.components.forms.input', [ + 'title' => $this->getTitle(), + 'name' => $this->getName(), + 'requestName' => $this->getRequestName(), + 'type' => $this->getType(), + 'value' => $this->getValue() + ]); + } +} diff --git a/resources/views/private/components/forms/input.blade.php b/resources/views/private/components/forms/input.blade.php new file mode 100644 index 0000000..2550e3a --- /dev/null +++ b/resources/views/private/components/forms/input.blade.php @@ -0,0 +1,7 @@ +
+ + + @error($name) + {{ $message }} + @enderror +