From 5cdef59892bbd78143e647ed84b7b4b5d3a896a5 Mon Sep 17 00:00:00 2001 From: Poseidon281 Date: Tue, 11 Jun 2024 19:37:55 +0200 Subject: [PATCH] Added Limit option --- app/Filament/Resources/SettingResource.php | 8 ++ app/Models/Setting.php | 14 ++- composer.json | 1 + composer.lock | 86 ++++++++++++++++++- .../2024_05_19_154057_recreate_settings.php | 6 +- .../en/character-counter.php | 6 ++ .../nl/character-counter.php | 6 ++ 7 files changed, 114 insertions(+), 13 deletions(-) create mode 100644 lang/vendor/filament-character-counter/en/character-counter.php create mode 100644 lang/vendor/filament-character-counter/nl/character-counter.php diff --git a/app/Filament/Resources/SettingResource.php b/app/Filament/Resources/SettingResource.php index 3f7f95b562..bed42f0092 100644 --- a/app/Filament/Resources/SettingResource.php +++ b/app/Filament/Resources/SettingResource.php @@ -9,6 +9,7 @@ use Filament\Tables\Table; use Filament\Forms\Components\TextInput; use Filament\Forms\Components\Select; +use Schmeits\FilamentCharacterCounter\Forms\Components\TextInput as LimitInput; class SettingResource extends Resource { @@ -59,6 +60,13 @@ public static function table(Table $table): Table ->placeholder($record->description) ->type('number'), ], + 'limit' => [ + LimitInput::make('value') + ->label($record->label) + ->maxLength($record->limit) + ->showInsideControl(false) + ->placeholder($record->description), + ], default => [ TextInput::make('value') ->label($record->label) diff --git a/app/Models/Setting.php b/app/Models/Setting.php index 93cddf46e4..1cefee7a69 100644 --- a/app/Models/Setting.php +++ b/app/Models/Setting.php @@ -10,14 +10,10 @@ class Setting extends Model public $incrementing = false; - protected $fillable = ['key', 'label', 'value', 'type', 'attributes', 'description']; + protected $fillable = ['key', 'label', 'value', 'type', 'attributes', 'description', 'limit']; - protected $casts = ['attributes' => 'array']; - - public static function getValue($key) - { - $setting = static::where('key', $key)->first(); - - return $setting ? $setting->value : null; - } + protected $casts = [ + 'attributes' => 'array', + 'limit' => 'integer', + ]; } diff --git a/composer.json b/composer.json index 399b42278f..8cdc66cf54 100644 --- a/composer.json +++ b/composer.json @@ -31,6 +31,7 @@ "prologue/alerts": "^1.2", "ryangjchandler/blade-tabler-icons": "^2.3", "s1lentium/iptools": "~1.2.0", + "schmeits/filament-character-counter": "^1.2", "spatie/laravel-fractal": "^6.2", "spatie/laravel-query-builder": "^5.8.1", "spatie/temporary-directory": "^2.2", diff --git a/composer.lock b/composer.lock index ba784fff9a..ea466396ba 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": "bf44faee3aae2b1d4c1b57893c1aba98", + "content-hash": "83530d4270840e00bb42035ffebe7473", "packages": [ { "name": "abdelhamiderrahmouni/filament-monaco-editor", @@ -6579,6 +6579,88 @@ }, "time": "2022-08-17T14:28:59+00:00" }, + { + "name": "schmeits/filament-character-counter", + "version": "1.2.3", + "source": { + "type": "git", + "url": "https://github.com/schmeits/filament-character-counter.git", + "reference": "5810340bac36b5cd493115e40fb9e6f693ff59de" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/schmeits/filament-character-counter/zipball/5810340bac36b5cd493115e40fb9e6f693ff59de", + "reference": "5810340bac36b5cd493115e40fb9e6f693ff59de", + "shasum": "" + }, + "require": { + "filament/filament": "^3.2", + "filament/forms": "^3.2", + "php": "^8.1", + "spatie/laravel-package-tools": "^1.16.0" + }, + "require-dev": { + "laravel/pint": "^1.0", + "nunomaduro/collision": "^7.10", + "nunomaduro/larastan": "^2.9", + "orchestra/testbench": "^v8.22", + "pestphp/pest": "^2.34", + "pestphp/pest-plugin-arch": "^2.7", + "pestphp/pest-plugin-laravel": "^2.3", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "spatie/laravel-ray": "^1.36" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Schmeits\\FilamentCharacterCounter\\FilamentCharacterCounterServiceProvider" + ], + "aliases": { + "FilamentCharacterCounter": "Schmeits\\FilamentCharacterCounter\\Facades\\FilamentCharacterCounter" + } + } + }, + "autoload": { + "psr-4": { + "Schmeits\\FilamentCharacterCounter\\": "src/", + "Schmeits\\FilamentCharacterCounter\\Database\\Factories\\": "database/factories/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tally Schmeits", + "email": "tally@schmeits.com", + "role": "Developer" + } + ], + "description": "This is a Filament character counter TextField and Textarea form field for Filament v3.2", + "homepage": "https://github.com/schmeits/filament-character-counter", + "keywords": [ + "filament", + "filament-character-counter", + "filament-plugin", + "laravel", + "schmeits" + ], + "support": { + "issues": "https://github.com/schmeits/filament-character-counter/issues", + "source": "https://github.com/schmeits/filament-character-counter" + }, + "funding": [ + { + "url": "https://github.com/schmeits", + "type": "github" + } + ], + "time": "2024-05-29T07:52:57+00:00" + }, { "name": "spatie/color", "version": "1.5.3", @@ -13141,5 +13223,5 @@ "ext-zip": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/database/migrations/2024_05_19_154057_recreate_settings.php b/database/migrations/2024_05_19_154057_recreate_settings.php index c93a7b275e..ce8994c320 100644 --- a/database/migrations/2024_05_19_154057_recreate_settings.php +++ b/database/migrations/2024_05_19_154057_recreate_settings.php @@ -20,7 +20,8 @@ public function up(): void $table->text('value')->nullable(); $table->json('attributes')->nullable(); $table->string('type'); - $table->longText('description'); + $table->longText('description')->nullable(); + $table->integer('limit')->nullable(); $table->timestamps(); }); @@ -28,7 +29,8 @@ public function up(): void 'key' => 'APP_NAME', 'label' => 'Panel Name', 'value' => 'Pelican', - 'type' => 'text', + 'type' => 'limit', + 'limit' => 18, 'description' => 'This is the name that is used throughout the panel and in emails sent to clients.', ]); diff --git a/lang/vendor/filament-character-counter/en/character-counter.php b/lang/vendor/filament-character-counter/en/character-counter.php new file mode 100644 index 0000000000..f81b8128a6 --- /dev/null +++ b/lang/vendor/filament-character-counter/en/character-counter.php @@ -0,0 +1,6 @@ + ' / ', + 'character_label' => 'characters', +]; diff --git a/lang/vendor/filament-character-counter/nl/character-counter.php b/lang/vendor/filament-character-counter/nl/character-counter.php new file mode 100644 index 0000000000..3dc9071b70 --- /dev/null +++ b/lang/vendor/filament-character-counter/nl/character-counter.php @@ -0,0 +1,6 @@ + ' / ', + 'character_label' => 'karakters', +];