| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- namespace App\Http\Requests;
- use Illuminate\Foundation\Http\FormRequest;
- class CustomScheduleRequest 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>
- */
- public function rules(): array
- {
- $rules = [
- 'client_id' => 'required|exists:clients,id',
- 'address_id' => 'required|exists:addresses,id',
- 'address_type' => 'required|in:home,commercial',
- 'service_type_id' => 'required|exists:service_types,id',
- 'description' => 'nullable|string',
- 'min_price' => 'required|numeric|min:0',
- 'max_price' => 'required|numeric|min:0|gte:min_price',
- 'offers_meal' => 'nullable|boolean',
- 'date' => 'required|date|after_or_equal:today',
- 'period_type' => 'required|in:2,4,6,8',
- 'start_time' => 'required|date_format:H:i',
- 'end_time' => 'required|date_format:H:i|after:start_time',
- 'quantity' => 'nullable|integer|min:1|max:10',
- 'speciality_ids' => 'nullable|array',
- 'speciality_ids.*' => 'exists:specialities,id',
- ];
- if ($this->isMethod('PUT') || $this->isMethod('PATCH')) {
- foreach ($rules as $key => $rule) {
- if (str_starts_with($rule, 'required')) {
- $rules[$key] = 'sometimes|' . substr($rule, 9);
- }
- }
- }
- return $rules;
- }
- /**
- * Get custom messages for validator errors.
- */
- public function messages(): array
- {
- return [
- 'max_price.gte' => 'O preço máximo deve ser maior ou igual ao preço mínimo.',
- 'date.after_or_equal' => 'A data deve ser hoje ou uma data futura.',
- 'end_time.after' => 'O horário de término deve ser posterior ao horário de início.',
- ];
- }
- }
|