$platforms */ public function __construct(private Collection $platforms) {} /** * @param Closure(string, ?string=): PotentiallyTranslatedString $fail */ public function validate(string $attribute, mixed $value, Closure $fail): void { $content = (string) $value; $reported = []; foreach ($this->platforms as $platform) { if (! $platform instanceof Platform) { continue; } if (isset($reported[$platform->value])) { continue; } $over = $platform->contentOverflow($content); if ($over === 0) { continue; } $reported[$platform->value] = true; $fail(trans('posts.form.content_exceeds_platform', [ 'platform' => $platform->label(), 'limit' => $platform->maxContentLength(), 'over' => $over, ])); } } }