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

Your argument inside with needs to match the method name for your relationship. In other words, if you do this:

$project = Projects::with("worknotes")->findOrFail($id);

Then, in order to eager load the relationships, your relationship's method's name needs to match:

// Note that I named the function "worknotes()", not "project_worknotes()".
public function worknotes(){
    return $this->hasMany("App\models\worknotes");
}

Both have to be called either "worknotes" or both have to be called "project_worknotes". Choose one or the other.

Next, if you want to get nested relationships, you can do that with the dot notation.

$project = Projects::with("worknotes", "worknotes.attachments")->findOrFail($id);
Last updated 8 years ago.
0

Hi thomastkim,

Thanks! its working. The dot notation is what i'm missing.

Thanks!

0

Sign in to participate in this thread!

Eventy

Your banner here too?

treblemdp treblemdp Joined 14 Sep 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.