Skip to content

Commit

Permalink
Cria função para adicionar substituição de caracteres
Browse files Browse the repository at this point in the history
  • Loading branch information
edineivaldameri committed Jun 1, 2023
1 parent 526ace8 commit 0138c70
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion app/Http/Controllers/Api/PostalCodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,20 @@ public function search(Client $http, $postalCode)
return response()->json([
'postal_code' => $data->cep,
'address' => $data->logradouro,
'complement' => preg_replace("/[^a-zA-Z0-9 \/–\ .]/", '', $data->complemento),
'complement' => $this->getClearComplementByRuleEducacenso($data->complemento),
'neighborhood' => $data->bairro,
'city_name' => $data->localidade,
'state_abbreviation' => $data->uf,
'city_ibge_code' => intval($data->ibge),
'city' => $city->only(['id', 'state_id', 'name', 'ibge_code']),
]);
}

private function getClearComplementByRuleEducacenso(string $complement): string
{
$comAcentos = ['à', 'á', 'â', 'ã', 'ä', 'å', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', 'ù', 'ü', 'ú', 'ÿ', 'À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', 'O', 'Ù', 'Ü', 'Ú'];
$semAcentos = ['a', 'a', 'a', 'a', 'a', 'a', 'c', 'e', 'e', 'e', 'e', 'i', 'i', 'i', 'i', 'n', 'o', 'o', 'o', 'o', 'o', 'u', 'u', 'u', 'y', 'A', 'A', 'A', 'A', 'A', 'A', 'C', 'E', 'E', 'E', 'E', 'I', 'I', 'I', 'I', 'N', 'O', 'O', 'O', 'O', 'O', 'O', 'U', 'U', 'U'];

return preg_replace("/[^a-zA-Z0-9 \/–\ .]/", '', str_replace($comAcentos, $semAcentos, $complement));
}
}

0 comments on commit 0138c70

Please sign in to comment.