kTat's avatar
Level 1

Using `whereHas` across two databases

Hi, I've come across a problem where trying to check existence of relationship with whereHas between entity in the default database and entity that exists in a separate database doesn't work because Laravel still looks for the entity in the default database... does anyone have any idea? Thanks!

0 likes
2 replies
jekinney's avatar

@kTat You can set the database connection per model:

protected $connection= 'second_db_connection';

and you can use the:

Model::on('conection_to_database')->get();

@staudenmeir Not a true statement.

Please or to participate in this conversation.