diff --git a/app/Http/Requests/Concerns/HasImageUploads.php b/app/Http/Requests/Concerns/HasImageUploads.php index 305dc321..082a2c9b 100644 --- a/app/Http/Requests/Concerns/HasImageUploads.php +++ b/app/Http/Requests/Concerns/HasImageUploads.php @@ -2,14 +2,21 @@ namespace App\Http\Requests\Concerns; +use App\Rules\FilenameLengthRule; + trait HasImageUploads { - public function uploadedImageRules(): string + public function uploadedImageRules(): array { $max_filesize = $this->maxFilesize() * 1000; $allowed_mimes = implode(',', $this->supportedMimes()); - return "mimes:$allowed_mimes|min:1|max:$max_filesize"; + return [ + "mimes:{$allowed_mimes}", + "min:1", + "max:{$max_filesize}", + new FilenameLengthRule(maxLength: 200), + ]; } public function uploadedImageMessages(string $rule): string diff --git a/app/Rules/FilenameLengthRule.php b/app/Rules/FilenameLengthRule.php new file mode 100644 index 00000000..574f309f --- /dev/null +++ b/app/Rules/FilenameLengthRule.php @@ -0,0 +1,25 @@ +getClientOriginalName(); + + if (strlen($name) > $this->maxLength) { + $fail("The :attribute filename must not exceed {$this->maxLength} characters."); + } + } +} \ No newline at end of file diff --git a/resources/views/profiles/edit/information.blade.php b/resources/views/profiles/edit/information.blade.php index ba3c214a..6e75afdb 100644 --- a/resources/views/profiles/edit/information.blade.php +++ b/resources/views/profiles/edit/information.blade.php @@ -6,6 +6,12 @@
+ Image requirements +
@@ -24,6 +30,7 @@
+ Image requirements
diff --git a/resources/views/profiles/edit/news.blade.php b/resources/views/profiles/edit/news.blade.php index 89595643..5de24f1d 100644 --- a/resources/views/profiles/edit/news.blade.php +++ b/resources/views/profiles/edit/news.blade.php @@ -37,7 +37,7 @@ -
+
+ Image requirements + @foreach ($errors->get("data.{$news->id}.image") as $image_error) @include('alert', ['message' => $image_error, 'type' => 'danger'])

{!! $image_error !!}