Skip to content
Discussion options

You must be logged in to vote

Laravel doesn't support this kind of relationship because the SQL query would have to join a different table depending on the value of champion_type and that's not possible.

I created a package for complex cases like this that allows you to merge multiple relationships, but it requires a bit of setup:
https://github.com/staudenmeir/laravel-merged-relations

In your case, you would merge the two HasOneThrough relationships modelA and modelB. Also, the package currently doesn't offer a way to only return a single related result, only a collection. You would have to manually take the first collection item (e.g. with an accessor).

Replies: 4 comments 11 replies

Comment options

You must be logged in to vote
1 reply
@JeffreyDavidson
Comment options

Comment options

You must be logged in to vote
2 replies
@JeffreyDavidson
Comment options

@JeffreyDavidson
Comment options

Comment options

You must be logged in to vote
8 replies
@staudenmeir
Comment options

@cwilby
Comment options

@staudenmeir
Comment options

@cwilby
Comment options

@edalzell
Comment options

Answer selected by JeffreyDavidson
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
5 participants