Skip to content

Relationships with two databases #189

Answered by powlam
powlam asked this question in Q&A
Mar 23, 2023 · 2 comments · 3 replies
Discussion options

You must be logged in to vote

I've found a way... The model of the external table must be defined in a different way: adding the database name to the $table instead of changing the $connection.

class Employee extends Model
{
    protected $table = 'activeemployees.employees';
}

This way the database name is added to all the queries involving the external table.

Credits to https://laracasts.com/discuss/channels/eloquent/how-to-properly-use-2-database-relationships?reply=603694

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@powlam
Comment options

@staudenmeir
Comment options

@powlam
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by staudenmeir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants