I have a Notification which implements
public function notifiable()
{
return $this->morphTo();
}
public function receiver()
{
return $this->belongsTo('User');
}
public function sender()
{
return $this->belongsTo('User');
}
And different classes (Comment for ex)
public function notifications()
{
return $this->morphMany('Notification', 'notifiable');
}
public function answer()
{
return $this->belongsTo('Answer');
}
public function commenter()
{
return $this->belongsTo('User', 'user_id');
}
...
Using the NotificationRepository I would like to eger load the answers for each comment
public function paged()
{
$rows = $this->model
->with('notifiable.answer.report.user')
->latestForUser($this->user->id)
->simplePaginate($this->perPage);
return $rows;
}
The above code won't eger load the whole relationship tree and I end up with A LOT of queries for each user, report and answer when listing each notification (in notifications.index)
What am I doing wrong?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community