问题
Hello so I have system that showing comment data per post in admin dashboard but I got problem here, So I already showing the data in dashboard but my comment data got retrieve 2 times and I don't know why
here is my function in controller
public function getCommentPost($id){
$user = Auth::user();
$compalls = $user->posts;
foreach ($compalls as $key => $value) {
$compalls[$key]->comment_all = Idea::where('id_post', $id)->get();
}
return view('admin.comment_all', compact('compalls'));
}
this is the return image
hope you guys can help me thanks
Ok I add my code in view it simple look like this
foreach ($compalls as $compall)
<tr>
@foreach ($compall->coment_all as $coment)
<td>{{ $coment->id_user }}</td>
<td>{{ $coment->title }}</td>
@endforeach
</tr>
@endforeach
here is my model on Post.php
public function comments(){
return $this->hasMany(Comment::class);
}
来源:https://stackoverflow.com/questions/52436032/data-on-laravel-got-retrieve-2-times