From e7309a23e32bb099b438c8e3f67bc88f3c70a434 Mon Sep 17 00:00:00 2001
From: Krzysztof Grzelak <51724541+kgrzelak@users.noreply.github.com>
Date: Sat, 20 Jan 2024 15:42:14 +0100
Subject: [PATCH] dev (#1)
---
.gitignore | 8 ++
composer.json | 34 +++++++++
config/laravel-form.php | 13 ++++
resources/views/_attributes.blade.php | 3 +
resources/views/input.blade.php | 9 +++
resources/views/radio.blade.php | 9 +++
resources/views/select.blade.php | 10 +++
src/Items/Attributes.php | 26 +++++++
src/Items/BaseItem.php | 102 ++++++++++++++++++++++++++
src/Items/FormInput.php | 11 +++
src/Items/FormSelect.php | 12 +++
src/LaravelForm.php | 19 +++++
src/LaravelFormServiceProvider.php | 16 ++++
13 files changed, 272 insertions(+)
create mode 100644 .gitignore
create mode 100644 composer.json
create mode 100644 config/laravel-form.php
create mode 100644 resources/views/_attributes.blade.php
create mode 100644 resources/views/input.blade.php
create mode 100644 resources/views/radio.blade.php
create mode 100644 resources/views/select.blade.php
create mode 100644 src/Items/Attributes.php
create mode 100644 src/Items/BaseItem.php
create mode 100644 src/Items/FormInput.php
create mode 100644 src/Items/FormSelect.php
create mode 100644 src/LaravelForm.php
create mode 100644 src/LaravelFormServiceProvider.php
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c253173
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,8 @@
+
+.idea/
+
+composer.lock
+
+vendor/
+
+test.php
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..eab758d
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,34 @@
+{
+ "name": "kgrzelak/laravel-form",
+ "license": "MIT",
+ "authors": [
+ {
+ "name": "Krzysztof Grzelak",
+ "email": "krzysztof@grzelak.dev",
+ "homepage": "https://grzelak.dev"
+ }
+ ],
+ "require": {
+ "php": "^8.2",
+ "spatie/laravel-package-tools": "^1.16.1",
+ "illuminate/bus": "^10.0",
+ "illuminate/conditionable": "^10.0",
+ "illuminate/console": "^10.0",
+ "illuminate/database": "^10.0",
+ "illuminate/pipeline": "^10.0",
+ "illuminate/support": "^10.0",
+ "laravel/framework": "^10.41"
+ },
+ "autoload": {
+ "psr-4": {
+ "Kgrzelak\\LaravelForm\\": "src"
+ }
+ },
+ "extra": {
+ "laravel": {
+ "providers": [
+ "Kgrzelak\\LaravelForm\\LaravelFormServiceProvider"
+ ]
+ }
+ }
+}
diff --git a/config/laravel-form.php b/config/laravel-form.php
new file mode 100644
index 0000000..8ac3ea8
--- /dev/null
+++ b/config/laravel-form.php
@@ -0,0 +1,13 @@
+ [
+ 'class' => 'form-control'
+ ],
+
+ 'select' => [
+ 'class' => 'form-select'
+ ]
+
+];
\ No newline at end of file
diff --git a/resources/views/_attributes.blade.php b/resources/views/_attributes.blade.php
new file mode 100644
index 0000000..b681226
--- /dev/null
+++ b/resources/views/_attributes.blade.php
@@ -0,0 +1,3 @@
+@foreach($attributes as $key => $value)
+{{ $key }}="{{ $value }}"
+@endforeach
\ No newline at end of file
diff --git a/resources/views/input.blade.php b/resources/views/input.blade.php
new file mode 100644
index 0000000..ed2e2aa
--- /dev/null
+++ b/resources/views/input.blade.php
@@ -0,0 +1,9 @@
+
+@error($name)
+
+ {{ $message }}
+
+@enderror
diff --git a/resources/views/radio.blade.php b/resources/views/radio.blade.php
new file mode 100644
index 0000000..2049bd3
--- /dev/null
+++ b/resources/views/radio.blade.php
@@ -0,0 +1,9 @@
+
+@error($name)
+
+ {{ $message }}
+
+@enderror
\ No newline at end of file
diff --git a/resources/views/select.blade.php b/resources/views/select.blade.php
new file mode 100644
index 0000000..b7b93d0
--- /dev/null
+++ b/resources/views/select.blade.php
@@ -0,0 +1,10 @@
+
+@error($name)
+
+ {{ $message }}
+
+@enderror
\ No newline at end of file
diff --git a/src/Items/Attributes.php b/src/Items/Attributes.php
new file mode 100644
index 0000000..6f00aa7
--- /dev/null
+++ b/src/Items/Attributes.php
@@ -0,0 +1,26 @@
+ $this->attributes
+ ])->render();
+ }
+
+ public function __toString()
+ {
+ return $this->toHtml();
+ }
+}
\ No newline at end of file
diff --git a/src/Items/BaseItem.php b/src/Items/BaseItem.php
new file mode 100644
index 0000000..9be7fc7
--- /dev/null
+++ b/src/Items/BaseItem.php
@@ -0,0 +1,102 @@
+id = $id;
+
+ return $this;
+ }
+
+ public function setName(string $name): static
+ {
+ $this->name = $name;
+
+ return $this;
+ }
+
+ public function setType(string $type): static
+ {
+ $this->type = $type;
+
+ return $this;
+ }
+
+ public function setValue(string $value): static
+ {
+ $this->value = $value;
+
+ return $this;
+ }
+
+ public function setPlaceholder(string $placeholder): static
+ {
+ $this->placeholder = $placeholder;
+
+ return $this;
+ }
+
+ public function setAttributes(array $attributes): static
+ {
+ $this->attributes = $attributes;
+
+ return $this;
+ }
+
+ public function setRequired(bool $required): static
+ {
+ $this->required = $required;
+
+ return $this;
+ }
+
+ public function setClass(string $class): static
+ {
+ $this->class = $class;
+
+ return $this;
+ }
+
+ public function toHtml(): string
+ {
+ return view('laravel-form::' . $this->viewName, [
+ 'id' => $this->id,
+ 'name' => $this->name,
+ 'class' => $this->class,
+ 'type' => $this->type,
+ 'value' => $this->value,
+ 'placeholder' => $this->placeholder,
+ 'attributes' => new Attributes($this->attributes),
+ 'required' => $this->required
+ ])->render();
+ }
+
+ public function __toString(): string
+ {
+ return $this->toHtml();
+ }
+}
\ No newline at end of file
diff --git a/src/Items/FormInput.php b/src/Items/FormInput.php
new file mode 100644
index 0000000..2bab771
--- /dev/null
+++ b/src/Items/FormInput.php
@@ -0,0 +1,11 @@
+class = config('laravel-form.input.class', 'form-input');
+ }
+}
\ No newline at end of file
diff --git a/src/Items/FormSelect.php b/src/Items/FormSelect.php
new file mode 100644
index 0000000..a7c954b
--- /dev/null
+++ b/src/Items/FormSelect.php
@@ -0,0 +1,12 @@
+class = config('laravel-form.select.class', 'form-select');
+ $this->viewName = 'select';
+ }
+}
\ No newline at end of file
diff --git a/src/LaravelForm.php b/src/LaravelForm.php
new file mode 100644
index 0000000..f7c6540
--- /dev/null
+++ b/src/LaravelForm.php
@@ -0,0 +1,19 @@
+name('laravel-form')
+ ->hasConfigFile('laravel-form')
+ ->hasViews('laravel-form');
+ }
+}
\ No newline at end of file