Files
Plataforma-de-Tutoriais/plataforma-tutorias/app/Http/Requests/UpdateVideoRequest.php
2026-05-27 09:30:13 +01:00

61 lines
1.9 KiB
PHP

<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdateVideoRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
protected function prepareForValidation(): void
{
if ($this->has('order')) {
$this->merge([
'order' => (int) $this->order
]);
}
}
public function rules(): array
{
return [
'title' => 'sometimes|string|max:255',
'description' => 'sometimes|string|max:3000',
'url' => 'sometimes|string|max:500',
'thumbnail' => 'sometimes|file|mimes:jpg,jpeg,png,webp|max:4000',
'tags' => 'sometimes|string|max:100',
'category_ids' => 'sometimes|array',
'category_ids.*' => 'exists:categories,id',
'is_active' => 'sometimes|boolean',
'order' => 'sometimes|integer|min:0',
];
}
public function messages(): array
{
return [
'title.max' => 'O título deve ter no máximo 255 caracteres',
'description.max' => 'A descrição deve ter no máximo 3000 caracteres',
'url.max' => 'A URL deve ter no máximo 500 caracteres',
'thumbnail.mimes' => 'O ficheiro deve ser do formato jpg, jpeg, png ou webp',
'thumbnail.max' => 'A thumbnail deve ter no máximo 4MB',
'category_id.exists' => 'A categoria não existe',
'order.integer' => 'A ordem deve ser um número inteiro',
'order.min' => 'A ordem deve ser maior ou igual a 0',
];
}
}