Search Cep in another bank in Laravel 5 [duplicate]

1

I'm doing a registration system using Laravel 5, I created the client schema, with some tables, such as person, address, email, phone. happens I have another bank, called zip, where it has some tables like street, us, neighborhood, city. I am very new to this framework, all I could do was imitate other ready-made models. Registration is working, both the search in the bank and the inclusion. My question, how do I type the zip in an html and through that cep the input in the form fill the fields of street, city, neighborhood, state? Thank you.

Obs. I did this select in mysql, it worked, now I do not know how to implement it in laravel

USE cep;
        SELECT e.endereco_logradouro, b.bairro_descricao, c.cidade_descricao, u.uf_sigla, u.uf_descricao
        FROM endereco e, bairro b, cidade c, uf u
        WHERE e.bairro_codigo = b.bairro_codigo AND
        b.cidade_codigo = c.cidade_codigo AND
        c.uf_codigo = u.uf_codigo AND e.endereco_cep = 'variável'
    
asked by anonymous 25.04.2016 / 16:23

1 answer

1

You can configure more than one database in Laravel .

Example:

    'mysql' => array(
      'driver'    => 'mysql',
        'host'      => 'host',
        'database'  => 'database',
        'username'  => 'srvweb',
        'password'  => '...',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => ''
    ),

   'mysql_2' => array(
      'driver'    => 'mysql',
        'host'      => 'host',
        'database'  => 'database_2',
        'username'  => 'srvweb',
        'password'  => '...',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => ''
    ),

Note that you always have multiple settings in Laravel , for more than one type of SGDB. There is no problem setting up more than one bank for the same SGDB.

You should also have noticed another parameter called default that you should configure:

  'default' => 'mysql',

This is the default bank used in all of your Models.

My suggestion is that you configure another database, and in the Cep model, you will define that it will use the connection to another database.

    class Cep extends \Eloquent
    {
          protected $connection = 'mysql_2';

          // Outras definições
    }

From here on, just do the queries with this Model :

   $ceps = Cep::where('endereco', 'LIKE', 'valor%')->get();

It's just an "illustrative settings". You can use your creativity to better organize your project (and your time).

    
25.04.2016 / 19:07