我回来了 return $post->comments; 来自控制器。但我还需要归还 $post 与之关联。但是自从 $post->comments 返回多个实例,我甚至无法使用 ->with() 方法如下:
return $post->comments;
$post
$post->comments
->with()
return $post->comments->with('commentable')->get(); // BadMethodCallException: Method with does not exist.
这是一种多态关系。如何加载 *-able 相关型号?
*-able
必须将关系作为方法而不是属性调用:
return $post->comments()->with('commentable')->get();