AssociateValidationService.php 932 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Services;
  3. use App\Models\User;
  4. class AssociateValidationService
  5. {
  6. public function validate(array $data): ?User
  7. {
  8. return User::query()
  9. ->where(function ($query) use ($data) {
  10. if (!empty($data['cpf'])) {
  11. $query->orWhere(
  12. 'cpf',
  13. $data['cpf']
  14. );
  15. }
  16. if (!empty($data['registration'])) {
  17. $query->orWhere(
  18. 'registration',
  19. $data['registration']
  20. );
  21. }
  22. if (!empty($data['name'])) {
  23. $query->orWhere(
  24. 'name',
  25. 'like',
  26. '%' . $data['name'] . '%'
  27. );
  28. }
  29. })
  30. ->first();
  31. }
  32. }