data on laravel got retrieve 2 times

旧时模样 提交于 2019-12-08 12:13:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!