遇到以下代码麻烦
$feed = Feed::orderBy('updated_at', 'desc')
->with(['feedable' => function (MorphTo $morphTo) {
$morphTo->morphWith([
Post::class => ['user', 'images', 'likes', 'comments', 'comments.user'],
GroupPost::class => ['user', 'images', 'likes', 'comments', 'comments.user', 'group']
]);
}])
->paginate(10);
从https://laravel.com/docs/5.8/eloquent-relationships#eager-loading
获得用户的参考没有得到什么地方出了问题。 出现类似调用未定义方法Illuminate \ Database \ Eloquent \ Builder :: morphWith
的错误虽然延迟加载可以正常工作
$feed = Feed::orderBy('updated_at', 'desc')
->with('feedable')
->paginate(10)
->loadMorph('feedable', [
Post::class => ['user', 'images', 'likes', 'comments', 'comments.user'],
GroupPost::class => ['user', 'images', 'likes', 'comments', 'comments.user', 'group'],
]);
请帮助解决此问题。