Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 1 year ago.
0

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.

Cheers

0

Sign in to participate in this thread!

Eventy

Your banner here too?

eheitman eheitman Joined 9 Jun 2015

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.