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);
Hi thomastkim,
Thanks! its working. The dot notation is what i'm missing.
Thanks!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community