1

I have two databases ("internal" and "external") and I would like to create a BelongsToMany relation between them. The problem, how do I specify in which database the relation_table is stored?

In my current case, I have some users that I would like to connect to some objects from an external database.

User:

public function objects() {
    return $this->belongsToMany('\App\Object', 'user_object_relation');
}

Object:

protected $connection = 'mysql_data';
protected $table = 'objects';
protected $primaryKey = 'ObjectID';

Eloquent now is assuming my user_object_relation table in the mysql_data (external) database, however I've created this in the "internal" database.

Q: How do I tell eloquent that the relation table is not in the external table?

// edit:

with return $this->belongsToMany('\App\Object', 'internal.user_object_relation');, I receive an access denied error because the "external" database user has no access to the internal ;)

wiesson
  • 6,544
  • 5
  • 40
  • 68
  • possible duplicate of [belongsToMany relationship in Laravel across multiple databases](http://stackoverflow.com/questions/25142968/belongstomany-relationship-in-laravel-across-multiple-databases) – wiesson Apr 27 '15 at 09:41

0 Answers0