ClassRequest.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Validation\Rule;
  5. class ClassRequest extends FormRequest
  6. {
  7. public function authorize(): bool
  8. {
  9. return true;
  10. }
  11. public function rules(): array
  12. {
  13. $required = $this->isMethod('POST') ? 'required' : 'sometimes';
  14. return [
  15. 'title' => "{$required}|string|max:255",
  16. 'class_package_unit_id' => [
  17. $required,
  18. 'integer',
  19. Rule::exists('class_package_units', 'id')
  20. ->where('unit_id', $this->input('active_unit_id')),
  21. ],
  22. 'instructor' => 'nullable|string|max:255',
  23. 'room' => 'nullable|string|max:255',
  24. 'date_time_start' => "{$required}|date",
  25. 'date_time_end' => "{$required}|date|after:date_time_start",
  26. 'status' => 'sometimes|string|max:50',
  27. ];
  28. }
  29. /**
  30. * Add custom messages when needed
  31. * public function messages(): array
  32. * {
  33. * return [
  34. * 'field.required' => __('message.algo'),
  35. * ];
  36. * }
  37. */
  38. }