Adapting code for LAravel, auto-fill CEP

-1

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

0

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

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.

link

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

    
11.01.2018 / 16:38