As simple as possible, create a route of type controller
as follows:
app \ Http \ routes.php
Route::controllers(
[
'cep' => 'CepController',
]
);
Then, create controller
:
app \ Http \ Controllers \ CepController.php
...
class CepController extends Controller
{
public function getIndex(Request $request)
{
$results = simplexml_load_file("http://cep.republicavirtual.com.br/web_cep.php?formato=xml&cep=" . $request->get('cep'));
return response()
->json($results);
}
...
}
...
If you visit the route route you will see something like:
SimpleXMLElement {#1470 ▼
+"resultado": "1"
+"resultado_txt": "sucesso - cep completo"
+"uf": "SP"
+"cidade": "Santa Bárbara D'Oeste"
+"bairro": "Jardim Santa Rita de Cássia"
+"tipo_logradouro": "Rua"
+"logradouro": "João Ribeiro"
}