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

Oh, I know my mistake. I have to create a one-to-many relationship instead of a many-to-many. Then it works :)

Last updated 1 year ago.
0

Okay that's not the solution :/ I definitely need a many-to-many-relationship because else I have the following problem:

If I want to get all researches and I eager load the research_costs table (which is a one-to-many relationship between it and researches) I get the costs for ALL levels within the array of ALL researches. But I need to have the costs only for the specific research, other wise it would be redundant.

In other words, I would like to access the costs like this

$researches[0]->research_costs

instead of

$researches[0]->research_costs[0]

I hope you understand the problem. Hence, I need to use a many-to-many relationship like explained above but it doesn't work :/

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

d3mueller d3mueller Joined 29 Aug 2014

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.