Feat: Добавлена валидация обложки курса

 Минимальные размеры: 400x300px
 Максимальный размер: 2MB
 Форматы: JPEG, PNG, WebP
 Подсказки в формах
 Кастомные сообщения об ошибках

Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
mirivlad 2026-03-26 12:24:28 +08:00
parent 731eb48537
commit 5ee549fbd1
3 changed files with 13 additions and 3 deletions

View File

@ -64,11 +64,15 @@ class CourseController extends Controller
'objectives' => 'nullable|string',
'category_id' => 'nullable|exists:course_categories,id',
'type' => 'required|in:standard,scorm,h5p',
'thumbnail' => 'nullable|image|max:2048',
'thumbnail' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:2048|dimensions:min_width=400,min_height=300',
'duration_minutes' => 'nullable|integer',
'passing_score' => 'nullable|integer|min:0|max:100',
'has_certificate' => 'boolean',
'is_active' => 'boolean',
], [
'thumbnail.dimensions' => 'Изображение должно быть не менее 400x300 пикселей. Ваш размер: :width x :height px',
'thumbnail.mimes' => 'Допустимые форматы: JPEG, PNG, WebP',
'thumbnail.max' => 'Максимальный размер файла: 2MB',
]);
$validated['slug'] = $validated['slug'] ?? Str::slug($validated['title']);
@ -114,11 +118,15 @@ class CourseController extends Controller
'objectives' => 'nullable|string',
'category_id' => 'nullable|exists:course_categories,id',
'type' => 'required|in:standard,scorm,h5p',
'thumbnail' => 'nullable|image|max:2048',
'thumbnail' => 'nullable|image|mimes:jpeg,png,jpg,webp|max:2048|dimensions:min_width=400,min_height=300',
'duration_minutes' => 'nullable|integer',
'passing_score' => 'nullable|integer|min:0|max:100',
'has_certificate' => 'boolean',
'is_active' => 'boolean',
], [
'thumbnail.dimensions' => 'Изображение должно быть не менее 400x300 пикселей. Ваш размер: :width x :height px',
'thumbnail.mimes' => 'Допустимые форматы: JPEG, PNG, WebP',
'thumbnail.max' => 'Максимальный размер файла: 2MB',
]);
$validated['slug'] = $validated['slug'] ?? Str::slug($validated['title']);

View File

@ -75,6 +75,7 @@
<div class="mb-3">
<label class="form-label">Обложка</label>
<input type="file" name="thumbnail" class="form-control" accept="image/*">
<small class="text-muted">Мин. 400x300px, макс. 2MB, форматы: JPEG, PNG, WebP</small>
</div>
</div>
</div>

View File

@ -72,7 +72,8 @@
<div class="mb-3">
<label class="form-label">Обложка</label>
<input type="file" name="thumbnail" class="form-control" accept="image/*">
@if($course->thumbnail)<small class="text-muted">Текущая: {{ basename($course->thumbnail) }}</small>@endif
@if($course->thumbnail)<small class="text-muted d-block">Текущая: {{ basename($course->thumbnail) }}</small>@endif
<small class="text-muted">Мин. 400x300px, макс. 2MB, форматы: JPEG, PNG, WebP</small>
</div>
</div>
</div>