【发布时间】:2019-08-09 11:35:30
【问题描述】:
我正在使用laravel 包commentable by faustbrian。我一直在使用就像在 github 中的文档中一样获得帖子的评论。我想搜索发布评论的用户的信息,例如用户头像、地址和其他信息。我想将用户信息(这是一个数组)包含到数组的当前位置索引中(而对于每个我推送它)。问题是,我也尝试使用array_push、array_merge 和$data[$key]=>$value。但是当我添加变量时,它们都不起作用。请帮忙。
public function notaPengurusan($id){
$comments=Complaint::findOrFail($id)->comments->toArray();
foreach ($comments as $comment){
$creator=User::findOrFail($comment['creator_id'])->toArray();
array_push($comment,$creator);
}
dd($comments);
return view('complaint::notapengurusan',compact('comments'));
}
【问题讨论】: