From bcfececb470c587d9e98a20a8c594844157bcd33 Mon Sep 17 00:00:00 2001 From: Dave Roverts Date: Tue, 9 Nov 2021 21:35:40 +0100 Subject: [PATCH 01/42] Add laravel-form-components. Published only bootstrap-4 stuff --- composer.json | 1 + composer.lock | 84 ++++++++++++++++++- config/form-components.php | 79 +++++++++++++++++ .../bootstrap-4/form-checkbox.blade.php | 28 +++++++ .../bootstrap-4/form-errors.blade.php | 5 ++ .../bootstrap-4/form-group.blade.php | 13 +++ .../bootstrap-4/form-input.blade.php | 44 ++++++++++ .../bootstrap-4/form-label.blade.php | 3 + .../bootstrap-4/form-radio.blade.php | 28 +++++++ .../bootstrap-4/form-range.blade.php | 27 ++++++ .../bootstrap-4/form-select.blade.php | 45 ++++++++++ .../bootstrap-4/form-submit.blade.php | 6 ++ .../bootstrap-4/form-textarea.blade.php | 23 +++++ .../bootstrap-4/form.blade.php | 19 +++++ 14 files changed, 404 insertions(+), 1 deletion(-) create mode 100644 config/form-components.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-checkbox.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-errors.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-group.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-input.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-label.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-radio.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-range.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-select.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-submit.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form-textarea.blade.php create mode 100644 resources/views/vendor/form-components/bootstrap-4/form.blade.php diff --git a/composer.json b/composer.json index b4938060..c17a155f 100644 --- a/composer.json +++ b/composer.json @@ -26,6 +26,7 @@ "livewire/livewire": "^2.3", "maatwebsite/excel": "^3.1", "predis/predis": "^1.1", + "protonemedia/laravel-form-components": "^3.2", "renatomarinho/laravel-page-speed": "^2.0", "spatie/laravel-activitylog": "^3.8", "tabuna/breadcrumbs": "^2.0" diff --git a/composer.lock b/composer.lock index 2c36f3a0..b2243d91 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5c0274a8bfa536c82720291da75201d5", + "content-hash": "973f932e017dc9d3b39f2ccded713fdd", "packages": [ { "name": "asm89/stack-cors", @@ -4806,6 +4806,88 @@ ], "time": "2021-10-05T19:02:38+00:00" }, + { + "name": "protonemedia/laravel-form-components", + "version": "3.2.0", + "source": { + "type": "git", + "url": "https://github.com/protonemedia/laravel-form-components.git", + "reference": "643f2bb229b1fe09b780dd728b7cc5d595b24385" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/protonemedia/laravel-form-components/zipball/643f2bb229b1fe09b780dd728b7cc5d595b24385", + "reference": "643f2bb229b1fe09b780dd728b7cc5d595b24385", + "shasum": "" + }, + "require": { + "illuminate/support": "^7.22.4 || ^8.0", + "php": "^7.4 || ^8.0", + "symfony/http-foundation": "^5.1.2" + }, + "require-dev": { + "livewire/livewire": "^2.0", + "mockery/mockery": "^1.3.3", + "orchestra/testbench-browser-kit": "^5.1 || ^6.0", + "phpunit/phpunit": "^8.5 || ^9.0", + "spatie/laravel-translatable": "^4.4", + "symfony/dom-crawler": "^5.1.14" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "ProtoneMedia\\LaravelFormComponents\\Support\\ServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "ProtoneMedia\\LaravelFormComponents\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Pascal Baljet", + "email": "pascal@protone.media", + "role": "Developer" + } + ], + "description": "Blade components to rapidly build forms with Tailwind CSS Custom Forms and Bootstrap 4.", + "homepage": "https://github.com/protonemedia/laravel-form-components", + "keywords": [ + "Forms", + "bootstrap", + "bootstrap-4", + "bootstrap-5", + "bootstrap4", + "bootstrap5", + "form", + "form-builder", + "form-components", + "laravel", + "laravel-form-builder", + "laravel-form-components", + "protonemedia", + "tailwind", + "tailwindcss" + ], + "support": { + "issues": "https://github.com/protonemedia/laravel-form-components/issues", + "source": "https://github.com/protonemedia/laravel-form-components/tree/3.2.0" + }, + "funding": [ + { + "url": "https://github.com/pascalbaljet", + "type": "github" + } + ], + "time": "2021-11-01T14:04:20+00:00" + }, { "name": "psr/container", "version": "1.1.2", diff --git a/config/form-components.php b/config/form-components.php new file mode 100644 index 00000000..6138db3c --- /dev/null +++ b/config/form-components.php @@ -0,0 +1,79 @@ + '', + + /** tailwind | tailwind-2 | bootstrap-4 | bootstrap-5 */ + 'framework' => 'bootstrap-4', + + 'use_eloquent_date_casting' => false, + + 'components' => [ + 'form' => [ + 'view' => 'form-components::{framework}.form', + 'class' => Components\Form::class, + ], + + 'form-checkbox' => [ + 'view' => 'form-components::{framework}.form-checkbox', + 'class' => Components\FormCheckbox::class, + ], + + 'form-errors' => [ + 'view' => 'form-components::{framework}.form-errors', + 'class' => Components\FormErrors::class, + ], + + 'form-group' => [ + 'view' => 'form-components::{framework}.form-group', + 'class' => Components\FormGroup::class, + ], + + 'form-input' => [ + 'view' => 'form-components::{framework}.form-input', + 'class' => Components\FormInput::class, + ], + + 'form-input-group' => [ + 'view' => 'form-components::{framework}.form-input-group', + 'class' => Components\FormInputGroup::class, + ], + + 'form-input-group-text' => [ + 'view' => 'form-components::{framework}.form-input-group-text', + 'class' => Components\FormInputGroupText::class, + ], + + 'form-label' => [ + 'view' => 'form-components::{framework}.form-label', + 'class' => Components\FormLabel::class, + ], + + 'form-radio' => [ + 'view' => 'form-components::{framework}.form-radio', + 'class' => Components\FormRadio::class, + ], + + 'form-range' => [ + 'view' => 'form-components::{framework}.form-range', + 'class' => Components\FormRange::class, + ], + + 'form-select' => [ + 'view' => 'form-components::{framework}.form-select', + 'class' => Components\FormSelect::class, + ], + + 'form-submit' => [ + 'view' => 'form-components::{framework}.form-submit', + 'class' => Components\FormSubmit::class, + ], + + 'form-textarea' => [ + 'view' => 'form-components::{framework}.form-textarea', + 'class' => Components\FormTextarea::class, + ], + ], +]; diff --git a/resources/views/vendor/form-components/bootstrap-4/form-checkbox.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-checkbox.blade.php new file mode 100644 index 00000000..8191b2ce --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-checkbox.blade.php @@ -0,0 +1,28 @@ +
+ merge(['class' => 'form-check-input ' . ($hasError($name) ? 'is-invalid' : '')]) !!} + type="checkbox" + value="{{ $value }}" + + @if($isWired()) + wire:model{!! $wireModifier() !!}="{{ $name }}" + @endif + + name="{{ $name }}" + + @if($label && !$attributes->get('id')) + id="{{ $id() }}" + @endif + + @if($checked) + checked="checked" + @endif + /> + + + + {!! $help ?? null !!} + + @if($hasErrorAndShow($name)) + + @endif +
\ No newline at end of file diff --git a/resources/views/vendor/form-components/bootstrap-4/form-errors.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-errors.blade.php new file mode 100644 index 00000000..59c618d6 --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-errors.blade.php @@ -0,0 +1,5 @@ +@error($name, $bag) +
merge(['class' => 'invalid-feedback']) !!}> + {{ $message }} +
+@enderror \ No newline at end of file diff --git a/resources/views/vendor/form-components/bootstrap-4/form-group.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-group.blade.php new file mode 100644 index 00000000..7222b9bc --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-group.blade.php @@ -0,0 +1,13 @@ +
merge(['class' => 'form-group ' . ($hasError($name) ? 'is-invalid' : '')]) !!}> + + +
+ {!! $slot !!} +
+ + {!! $help ?? null !!} + + @if($hasErrorAndShow($name)) + + @endif +
\ No newline at end of file diff --git a/resources/views/vendor/form-components/bootstrap-4/form-input.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-input.blade.php new file mode 100644 index 00000000..7961db7c --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-input.blade.php @@ -0,0 +1,44 @@ +
+ + +
+ @isset($prepend) +
+
+ {!! $prepend !!} +
+
+ @endisset + + merge(['class' => 'form-control ' . ($hasError($name) ? 'is-invalid' : '')]) !!} + type="{{ $type }}" + + @if($isWired()) + wire:model{!! $wireModifier() !!}="{{ $name }}" + @else + value="{{ $value }}" + @endif + + name="{{ $name }}" + + @if($label && !$attributes->get('id')) + id="{{ $id() }}" + @endif + /> + + @isset($append) +
+
+ {!! $append !!} +
+
+ @endisset + + @if($hasErrorAndShow($name)) + + @endif +
+ + {!! $help ?? null !!} + +
\ No newline at end of file diff --git a/resources/views/vendor/form-components/bootstrap-4/form-label.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-label.blade.php new file mode 100644 index 00000000..8536ce70 --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-label.blade.php @@ -0,0 +1,3 @@ +@if($label) + +@endif \ No newline at end of file diff --git a/resources/views/vendor/form-components/bootstrap-4/form-radio.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-radio.blade.php new file mode 100644 index 00000000..9e9f4784 --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-radio.blade.php @@ -0,0 +1,28 @@ +
+ merge(['class' => 'form-check-input ' . ($hasError($name) ? 'is-invalid' : '')]) !!} + type="radio" + + @if($isWired()) + wire:model{!! $wireModifier() !!}="{{ $name }}" + @endif + + name="{{ $name }}" + value="{{ $value }}" + + @if($checked) + checked="checked" + @endif + + @if($label && !$attributes->get('id')) + id="{{ $id() }}" + @endif + /> + + + + {!! $help ?? null !!} + + @if($hasErrorAndShow($name)) + + @endif +
\ No newline at end of file diff --git a/resources/views/vendor/form-components/bootstrap-4/form-range.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-range.blade.php new file mode 100644 index 00000000..e9f9221c --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-range.blade.php @@ -0,0 +1,27 @@ +
+ + + merge(['class' => 'form-control-range' . ($hasError($name) ? ' is-invalid' : '')]) !!} + + type="range" + + @if($isWired()) + wire:model{!! $wireModifier() !!}="{{ $name }}" + @else + value="{{ $value }}" + @endif + + name="{{ $name }}" + + @if($label && !$attributes->get('id')) + id="{{ $id() }}" + @endif + /> + + {!! $help ?? null !!} + + @if($hasErrorAndShow($name)) + + @endif +
diff --git a/resources/views/vendor/form-components/bootstrap-4/form-select.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-select.blade.php new file mode 100644 index 00000000..57206e14 --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-select.blade.php @@ -0,0 +1,45 @@ +
+ + + + + {!! $help ?? null !!} + + @if($hasErrorAndShow($name)) + + @endif +
\ No newline at end of file diff --git a/resources/views/vendor/form-components/bootstrap-4/form-submit.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-submit.blade.php new file mode 100644 index 00000000..6a79cd43 --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-submit.blade.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/resources/views/vendor/form-components/bootstrap-4/form-textarea.blade.php b/resources/views/vendor/form-components/bootstrap-4/form-textarea.blade.php new file mode 100644 index 00000000..0703a4aa --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form-textarea.blade.php @@ -0,0 +1,23 @@ +
+ + + + + {!! $help ?? null !!} + + @if($hasErrorAndShow($name)) + + @endif +
\ No newline at end of file diff --git a/resources/views/vendor/form-components/bootstrap-4/form.blade.php b/resources/views/vendor/form-components/bootstrap-4/form.blade.php new file mode 100644 index 00000000..f3371b99 --- /dev/null +++ b/resources/views/vendor/form-components/bootstrap-4/form.blade.php @@ -0,0 +1,19 @@ +
merge([ + 'class' => $hasError() ? 'needs-validation' : '' +]) !!}> + + +@unless(in_array($method, ['HEAD', 'GET', 'OPTIONS'])) + @csrf +@endunless + +@if($spoofMethod) + @method($method) +@endif + + {!! $slot !!} +
From 104c6191877af2703892ad292262c673be876cc5 Mon Sep 17 00:00:00 2001 From: Dave Roverts Date: Tue, 9 Nov 2021 22:17:00 +0100 Subject: [PATCH 02/42] Airport --- .../Requests/Airport/Admin/StoreAirport.php | 18 +++- .../Requests/Airport/Admin/UpdateAirport.php | 14 +++ app/Models/Airport.php | 10 +++ resources/views/airport/admin/form.blade.php | 90 ++++--------------- 4 files changed, 59 insertions(+), 73 deletions(-) diff --git a/app/Http/Requests/Airport/Admin/StoreAirport.php b/app/Http/Requests/Airport/Admin/StoreAirport.php index c63bccd0..32251388 100644 --- a/app/Http/Requests/Airport/Admin/StoreAirport.php +++ b/app/Http/Requests/Airport/Admin/StoreAirport.php @@ -14,9 +14,23 @@ class StoreAirport extends Request public function rules() { return [ - 'icao' => 'required:string|unique:airports|between:4,4', - 'iata' => 'required:string|unique:airports,iata|between:3,3', + 'icao' => 'required:string|unique:airports|size:4', + 'iata' => 'required:string|unique:airports,iata|size:3', 'name' => 'required:string', ]; } + + /** + * Get custom attributes for validator errors. + * + * @return array + */ + public function attributes() + { + return [ + 'icao' => __('ICAO'), + 'iata' => __('IATA'), + 'name' => __('Name'), + ]; + } } diff --git a/app/Http/Requests/Airport/Admin/UpdateAirport.php b/app/Http/Requests/Airport/Admin/UpdateAirport.php index f07b2f1a..92ad6cf9 100644 --- a/app/Http/Requests/Airport/Admin/UpdateAirport.php +++ b/app/Http/Requests/Airport/Admin/UpdateAirport.php @@ -19,4 +19,18 @@ public function rules() 'name' => 'required:string', ]; } + + /** + * Get custom attributes for validator errors. + * + * @return array + */ + public function attributes() + { + return [ + 'icao' => __('ICAO'), + 'iata' => __('IATA'), + 'name' => __('Name'), + ]; + } } diff --git a/app/Models/Airport.php b/app/Models/Airport.php index ddc41b7f..1d26fd11 100644 --- a/app/Models/Airport.php +++ b/app/Models/Airport.php @@ -80,6 +80,16 @@ public function links() return $this->hasMany(AirportLink::class); } + public function setIcaoAttribute($value) + { + $this->attributes['icao'] = strtoupper($value); + } + + public function setIataAttribute($value) + { + $this->attributes['iata'] = strtoupper($value); + } + public function getFullNameAttribute() { if (!$this->id) { diff --git a/resources/views/airport/admin/form.blade.php b/resources/views/airport/admin/form.blade.php index 15fc5190..314f9159 100644 --- a/resources/views/airport/admin/form.blade.php +++ b/resources/views/airport/admin/form.blade.php @@ -13,79 +13,27 @@
-
{{ $airport->id ? 'Edit' : 'Add new' }} Airport
+
{{ $airport->id ? __('Edit') : __('Add new') }} {{ __('Airport') }}
-
- @csrf - @if($airport->id) - @method('PATCH') - @endif - {{--ICAO--}} -
- - -
- - - @if ($errors->has('icao')) - - {{ $errors->first('icao') }} - - @endif -
-
- - {{--IATA--}} -
- - -
- - - @if ($errors->has('name')) - - {{ $errors->first('iata') }} - - @endif -
-
- - {{--Name--}} -
- - -
- - - @if ($errors->has('name')) - - {{ $errors->first('name') }} - - @endif -
-
- - {{--Add/Edit--}} -
-
- -
-
-
+ + + @bind($airport) + + + + + + @if ($airport->id) + Edit + @else + Add + @endif + + @endbind +
From 12765c90b348861dd83d944ad6aff1ca017b094e Mon Sep 17 00:00:00 2001 From: Dave Roverts Date: Tue, 9 Nov 2021 22:19:01 +0100 Subject: [PATCH 03/42] Added Forms Alert component so I don't have to repeat that part --- resources/js/components/ExampleComponent.vue | 23 ---- resources/views/airport/admin/form.blade.php | 10 +- .../views/airportLink/admin/form.blade.php | 66 +++++---- resources/views/booking/admin/edit.blade.php | 126 +++++++++--------- .../views/components/forms/alert.blade.php | 9 ++ .../views/event/admin/autoAssign.blade.php | 56 +++----- resources/views/event/admin/import.blade.php | 29 ++-- .../views/event/admin/routeAssign.blade.php | 17 +-- .../views/eventLink/admin/form.blade.php | 69 +++++----- resources/views/faq/admin/form.blade.php | 61 ++++----- 10 files changed, 198 insertions(+), 268 deletions(-) delete mode 100644 resources/js/components/ExampleComponent.vue create mode 100644 resources/views/components/forms/alert.blade.php diff --git a/resources/js/components/ExampleComponent.vue b/resources/js/components/ExampleComponent.vue deleted file mode 100644 index 2805329a..00000000 --- a/resources/js/components/ExampleComponent.vue +++ /dev/null @@ -1,23 +0,0 @@ - - - diff --git a/resources/views/airport/admin/form.blade.php b/resources/views/airport/admin/form.blade.php index 314f9159..4ff8c28f 100644 --- a/resources/views/airport/admin/form.blade.php +++ b/resources/views/airport/admin/form.blade.php @@ -1,15 +1,7 @@ @extends('layouts.app') @section('content') - @if (count($errors) > 0) -
-
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
-
- @endif +
diff --git a/resources/views/airportLink/admin/form.blade.php b/resources/views/airportLink/admin/form.blade.php index 8e767854..819a8915 100644 --- a/resources/views/airportLink/admin/form.blade.php +++ b/resources/views/airportLink/admin/form.blade.php @@ -1,15 +1,7 @@ @extends('layouts.app') @section('content') - @if (count($errors) > 0) -
-
    - @foreach ($errors->all() as $error) -
  • {{ $error }}
  • - @endforeach -
-
- @endif +
@@ -17,29 +9,30 @@
+ action="{{ $airportLink->id ? route('admin.airportLinks.update', $airportLink) : route('admin.airportLinks.store') }}"> @csrf - @if($airportLink->id) + @if ($airportLink->id) @method('PATCH') @endif - {{--Type--}} + {{-- Type --}}
- @@ -52,12 +45,12 @@ class="custom-select form-control{{ $errors->has('type') ? ' is-invalid' : '' }}
- {{--Airport--}} + {{-- Airport --}}
- @if($airportLink->id) + @if ($airportLink->id)
{{ $airportLink->airport->icao }} [{{ $airportLink->airport->name }} ({{ $airportLink->airport->iata }})] @@ -67,9 +60,10 @@ class="custom-select form-control{{ $errors->has('type') ? ' is-invalid' : '' }} class="custom-select form-control{{ $errors->has('airport_id') ? ' is-invalid' : '' }}" name="airport_id"> - @foreach($airports as $airport) - @endforeach @@ -77,21 +71,21 @@ class="custom-select form-control{{ $errors->has('airport_id') ? ' is-invalid' : @if ($errors->has('airport_id')) - {{ $errors->first('airport_id') }} - + {{ $errors->first('airport_id') }} + @endif @endif
- {{--Name--}} + {{-- Name --}}
+ class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" + value="{{ old('name', $airportLink->name) }}"> @if ($errors->has('name')) @@ -101,14 +95,14 @@ class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name"
- {{--URL--}} + {{-- URL --}}
+ class="form-control{{ $errors->has('url') ? ' is-invalid' : '' }}" name="url" + value="{{ old('url', $airportLink->url) }}" required> @if ($errors->has('url')) @@ -118,11 +112,11 @@ class="form-control{{ $errors->has('url') ? ' is-invalid' : '' }}" name="url"
- {{--Add/Edit--}} + {{-- Add/Edit --}}