Migration in more than one bank

Asked

Viewed 83 times

1

I need to turn the remote php artisan migrate and each Migration go to your respective database, I have the following code on .env:

DB_CONNECTION=mysql
DB_HOST=163.25.138.18
DB_PORT=3306
DB_DATABASE=book_posts
DB_USERNAME=teste
DB_PASSWORD=teste1

DB_BOOKLOGIN_CONNECTION=mysql
DB_BOOKLOGIN_HOST=163.25.138.18
DB_BOOKLOGIN_PORT=3306
DB_BOOKLOGIN_DATABASE=book_usuarios
DB_BOOKLOGIN_USERNAME=teste
DB_BOOKLOGIN_PASSWORD=teste1

DB_BOOKMATERIAIS_CONNECTION=mysql
DB_BOOKMATERIAIS_HOST=163.25.138.18
DB_BOOKMATERIAIS_PORT=3306
DB_BOOKMATERIAIS_DATABASE=book_materiais
DB_BOOKMATERIAIS_USERNAME=teste
DB_BOOKMATERIAIS_PASSWORD=teste1

I used the variable $connection in Migrations thus:

protected $connection = 'bookmateriais';

public function up()
{
    Schema::create('locais', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('nome');
        $table->timestamps();
        $table->softDeletes();
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */

public function down()
{
    Schema::dropIfExists('locals');
}

But when I spin php artisan migrate goes to the default bank, someone knows how to direct the Migration to their respective databases?

1 answer

2

I managed to solve!

For those who need follow the solution:

Schema::connection('bookmateriais')->create('locais', function (Blueprint $table) {
   $table->bigIncrements('id');
   $table->string('nome');
   $table->timestamps();
   $table->softDeletes();
});

Just use Connection after Schema::

Browser other questions tagged

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