SaveProductionOrderInstallationRequest.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Http\Requests;
  4. use App\Models\Role;
  5. use Illuminate\Database\Query\Builder;
  6. use Illuminate\Foundation\Http\FormRequest;
  7. use Illuminate\Validation\Rule;
  8. class SaveProductionOrderInstallationRequest extends FormRequest
  9. {
  10. public function authorize(): bool
  11. {
  12. return true;
  13. }
  14. /** @return array<string, mixed> */
  15. public function rules(): array
  16. {
  17. return [
  18. 'installation_date' => ['required', 'date'],
  19. 'installation_days' => ['required', 'integer', 'min:1', 'max:365'],
  20. 'brigadier_id' => [
  21. 'required',
  22. 'integer',
  23. Rule::exists('users', 'id')->where(
  24. fn (Builder $query): Builder => $query
  25. ->where('role', Role::BRIGADIER)
  26. ->whereNull('deleted_at'),
  27. ),
  28. ],
  29. 'note' => ['nullable', 'string', 'max:10000'],
  30. 'nav' => ['nullable', 'string', 'max:100'],
  31. ];
  32. }
  33. /** @return array<string, string> */
  34. public function attributes(): array
  35. {
  36. return [
  37. 'installation_date' => 'дата монтажа',
  38. 'installation_days' => 'количество дней монтажа',
  39. 'brigadier_id' => 'бригадир',
  40. ];
  41. }
  42. }