Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

Using 'legacy_db' as an example of the actual name for your old database, would this work?

class Topic extends Eloquent
{
    protected $primaryKey = 'token';

    public function members()
    {
        $relation = $this->belongsToMany('Member');
        $relation->table = 'legacy_db.legacy_members_table';
        return $relation;
    }   
}
Last updated 2 years ago.
0
Last updated 2 years ago.
0

OK, I figured it out (after some sleep). Thanks @thevelement to point me into the right direction.

Simply specify [database].[table_name] as the second argument of the relation

class Topic extends Eloquent
{
    protected $primaryKey = 'token';

    public function members()
    {
        retrun $this->belongsToMany('Member','legacy_db.legacy_members_table');
    }   
}
Last updated 2 years ago.
0

Was this really resolved? Are you truly using two distinct servers or just two different schemas?

Last updated 2 years ago.
0

I am still unable to do this across two server connections (vs two schemas).

0

You can do it across multiple server connections with Eloquent. It can get tricky when trying to query through Fluent.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.