Adapting code for LAravel, auto-fill CEP


Hello, I'm trying to adapt the code for this link: link for Laravel 5.2, without success. It works well without the framework, as for "css" and "js" I can import them into laravel. But I believe the problem is in the file "query_cep.php" that does not load. Any help already thanks. Thanks, Valdir

asked by anonymous 08.06.2016 / 13:29

2 answers


As simple as possible, create a route of type controller as follows:

app \ Http \ routes.php

        'cep' => 'CepController',

Then, create controller :

app \ Http \ Controllers \ CepController.php


class CepController extends Controller
    public function getIndex(Request $request)
        $results = simplexml_load_file("" . $request->get('cep'));

        return response()




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"
17.06.2016 / 15:36

I created a package for Laravel to communicate with the CepAberto , already does all the abstraction of the methods of consultation to cep, city, etc.


You can use it or use it as inspiration to create a package that you can refer to RepublicaVirtual

11.01.2018 / 16:38