Adapting Code to Laravel , CEP Automatic Fill

Asked

Viewed 1,908 times

0

2 answers

2


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

Http app Routes.php

Route::controllers(
    [
        'cep' => 'CepController',
    ]
);

So create the 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 http://seusite/cep? cep=13457091 you’ll 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"
}

1

  • I used your package, it works but often returns error 500 on the server.

  • @Does this have more details about the error? Notice in the Open Zip they have a limit of requests per seconds and also daily, it can be this limitation that is returning you 500, I will do tests because it should return a 403. If this is not your problem you pass me the data of the request that is returning you error so I can analyze and try to solve the problem.

  • is an intermittent problem, because the requests I make are to test the forms and has an interval between a request and another of at least 2 hours, I have no more details as it returns only error 500, already includes the key directly in the file thinking it was problems with the env(), even so it happens. I just used an example in pure php a little bit and tb is happening, I believe it is problems in the Cepaberto server.

  • @Wmomesso see there, if you get any more detail passes me that I see, anyway I will do some tests here to see if it happens to me tbm, it has been a while that I do not use this service.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.