联合模型获取的集合如何处理被联合那个模型的数据?
return Question::published()->with(['user' => function ($query){
$query->select(['id','name','avatar'])->get();
}])->get()->map(function ($item) {
$item->user->avatarUrl = Storage::url(config('custom.avatar').$item->user->avatar);
return $item;
});
像上面那样我想把提问题的用户里的头像进行处理,怎么样才能获取User模型的所有用户集合直接操作,而不用在Question集合中操作,毕竟Question集合中有很多用户是重复的
推荐文章: