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

Hi there,

I see this post is quite old, but I found it while googling to solve a similar problem. I didn't have two databases, but I needed a complex sql to resolve the relationship. What I ended up doing is extending the base class for relations and creating my own, right now in laravel 5.2 that is Illuminate\Database\Eloquent\Relations\Relation. It's quite self-explanatory implementing the abstract methods, but if you need any examples you can see the implementations of HasMany, BelongsTo, etc. all the relations that come with laravel out of the box.

Now, about the problem of having two databases, I think you'll have to do more than only implementing the abstract methods, since they are based on an already created query which I assume can be run only in one database, but I am sure you can get this to work by overriding whatever is necessary.

In another note, you can always create your custom queries or getting information wherever you want and create a collection of laravel models using the static ::hydrate() and ::hydrateRaw() methods in your model classes.



Sign in to participate in this thread!


Your banner here too?

eheitman eheitman Joined 9 Jun 2015


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

Your logo here?

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

© 2024 - All rights reserved.