fix: #51 - display news strip in mobile

This commit is contained in:
Noah Lancien 2024-07-24 12:19:47 +02:00
parent 2348aa5af7
commit 7e76ad9b02
3 changed files with 86 additions and 12 deletions

View file

@ -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',

View file

@ -0,0 +1,83 @@
<?php
namespace App\Rules;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Support\Str;
/**
* Check the length of a Wysiwyg field, excluding tags and end spaces.
*
* @package App\Rules
*/
class WysiwygLength implements ValidationRule
{
/**
* Construct method.
*
* @param integer $min The minimum length of the content (excluding tags). Default is 15.
* @param integer|null $max The maximum length of the content (excluding tags).
* Default is null (max will be defined by the type of the column in DB).
* @return void
* @throws \InvalidArgumentException If $max < $min.
*/
public function __construct(private int $min = 15, private int|null $max = null)
{
if ($max !== null && $max < $min && $min < 0) {
throw new \InvalidArgumentException(sprintf(
'$max should be higher than $min. $max = %d. $min = %d.',
$max,
$min
));
}
}
/**
* Run the validation rule.
*
* @param string $attribute
* @param mixed $value
* @param \Closure $fail
*
* @return void
*/
public function validate(string $attribute, mixed $value, \Closure $fail): void
{
$length = Str::length(\strip_tags($value));
$translatedAttribute = self::getTranslatedAttribute($attribute);
if (!\is_null($this->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;
}
}

View file

@ -258,7 +258,7 @@
</section>
{{-- STRIP --}}
@if ($stripModels->isNotEmpty())
<section class="strip bg-quad d-flex sticky-lg-bottom z-2 mt-5 overflow-hidden text-black">
<section class="strip bg-quad d-flex sticky-bottom z-2 mt-5 overflow-hidden text-black">
<div class="moving-strip d-flex" id="moving-strip">
@foreach ($stripModels as $stripModel)
@include('fo.partials.strips.strip-item')