From 7e76ad9b02bb9cd497d5c3d67b64ef8b61a68ea1 Mon Sep 17 00:00:00 2001 From: Noah Lancien Date: Wed, 24 Jul 2024 12:19:47 +0200 Subject: [PATCH] fix: #51 - display news strip in mobile --- .../Requests/Bo/Strips/StoreStripRequest.php | 13 +-- app/Rules/WysiwygLength.php | 83 +++++++++++++++++++ resources/views/fo/pages/home.blade.php | 2 +- 3 files changed, 86 insertions(+), 12 deletions(-) create mode 100644 app/Rules/WysiwygLength.php diff --git a/app/Http/Requests/Bo/Strips/StoreStripRequest.php b/app/Http/Requests/Bo/Strips/StoreStripRequest.php index d438903..2ecb5ba 100644 --- a/app/Http/Requests/Bo/Strips/StoreStripRequest.php +++ b/app/Http/Requests/Bo/Strips/StoreStripRequest.php @@ -2,9 +2,9 @@ namespace App\Http\Requests\Bo\Strips; +use App\Rules\WysiwygLength; use App\Traits\Requests\HasPicture; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Support\Str; use Illuminate\Validation\Rules\Enum; class StoreStripRequest extends FormRequest @@ -48,16 +48,7 @@ class StoreStripRequest extends FormRequest 'text' => [ 'required', 'string', - 'min:3', - // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundBeforeLastUsed - function (string $attribute, mixed $value, \Closure $fail) { - if (Str::wordCount(\strip_tags($value)) > 255) { - $fail(trans('validation.max_words', [ - 'attribute' => trans('validation.attributes.text'), - 'count' => '255' - ])); - } - } + new WysiwygLength(3, 90), ], 'news_id' => 'nullable|exists:news,id', 'published' => 'required|boolean', diff --git a/app/Rules/WysiwygLength.php b/app/Rules/WysiwygLength.php new file mode 100644 index 0000000..f57d257 --- /dev/null +++ b/app/Rules/WysiwygLength.php @@ -0,0 +1,83 @@ +max) and !($length >= $this->min && $length <= $this->max)) { + $fail(trans('validation.between.string', [ + 'attribute' => $translatedAttribute, + 'min' => $this->min, + 'max' => $this->max + ])); + return; + } + if ($length < $this->min) { + $fail(trans('validation.min.string', [ + 'attribute' => $translatedAttribute, + 'min' => $this->min + ])); + } + } + + /** + * Get the correct translation for the given attrribute. + * + * @param string $attribute + * @return string + */ + private static function getTranslatedAttribute(string $attribute): string + { + /** @var \Illuminate\Translation\Translator $trans */ + $trans = trans(); + if ($trans->has('validation.attributes.' . $attribute)) { + return trans('validation.attributes.' . $attribute); + } + if ($trans->has('validation.custom.' . $attribute)) { + return trans('validation.custom.' . $attribute); + } + return $attribute; + } +} diff --git a/resources/views/fo/pages/home.blade.php b/resources/views/fo/pages/home.blade.php index af1d6da..6fa5445 100644 --- a/resources/views/fo/pages/home.blade.php +++ b/resources/views/fo/pages/home.blade.php @@ -258,7 +258,7 @@ {{-- STRIP --}} @if ($stripModels->isNotEmpty()) -
+
@foreach ($stripModels as $stripModel) @include('fo.partials.strips.strip-item')