0

I have two database and inside each I have one table:

database_one -> one (table)
database_two -> two (table)

I would like to create a relationship Many-To-Many between two tables inside database_two; but the tables are in two different database.

This is my code for create a pivot table on the same database:

Schema::connection('database_two')->create('one_two', function (Blueprint $table) {

    $table->integer('one_id')->unsigned()->nullable();
    $table->foreign('one_id')->references('id')
        ->on('one')->onDelete('cascade');

    $table->integer('two_id')->unsigned()->nullable();
    $table->foreign('two_id')->references('id')
        ->on('two')->onDelete('cascade');

    $table->timestamps();

});

How can I do?

Thanks!

Mer
  • 93
  • 1
  • 1
  • 11
  • 1
    This might help you https://stackoverflow.com/questions/28598146/many-to-many-relationship-between-two-tables-in-two-different-databases – oBo Jun 29 '17 at 16:45

1 Answers1

1

laravel does not support relations across two databases:-)

Zulfiqar Tariq
  • 394
  • 3
  • 14
  • Depending on the situation it does. I've never tried it across different types of databases but say you're both DB's are mysql then you'd just need to specify the connection and you'd be good to go. – Rwd Jun 29 '17 at 17:14