Laravel使用hasmany获取信息时,希望对获取的指定每一个子元素的limit数量的方法。
$feed= Feed::whereUserId($userId)
->with(['comments'])
->get()
->map(function ($query) {
$query->setRelation('comments', $query->comments->take(10));
return $query;
});
宠物免费领养小程序,欢迎来踩