$this->relationLoaded() for distant relationships
Obviously you can load distant relationships like this...
$user->load('posts.comments.likes');
...but it seems you are unable to do something like this
if ($user->relationLoaded('posts.comments.likes')) {
// Do something.
}
Is there a nice way of checking if distant relations are loaded?
Thanks
$this->relationLoaded() only checks the $this->relations array keys, so it does not check distant relations.
You could do something like this..
$postsLoaded = $user->relationLoaded('posts');
$commentsLoaded = $user->posts->first()->relationLoaded('comments');
$likesLoaded = $user->posts->first()->comments->first()->relationLoaded('likes');
Please or to participate in this conversation.