Just for curious, why are you doing that?
In logs model:
class Log extend Eloquent
{
protected $connection = 'db2'; // config/database.php >> connections
}
We have an external log database for many apps.
If i define a new database connection in database.php and run a query like this
select * from log.logs
the query works fine. Even if i use joins but i want to use eloquent/query builder.
Oh! I misunderstand you. When you say 'database', then I think 'database server'. However I believe Eloquent does not supports this for now, as you can see in the db configuration: one database per connection so it's mean, at a time, a model has 1 connection, therefore, the relationship query will be built in the current database context.
Thank you @mejlo! It works like a charm. I only had to set the correct foreign keys on my relation.
@bomberman1990: Now you know it works. :p
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community