SQL命令未在Laravel 5.7中给出预期的结果。 我是否需要修改我的表格或查询?

I have my table data like below photo.

enter image description here

My expected data should be like this below photo.

enter image description here

My implemented laravel SQL code is like below.

$img = DB::table('table_name')
->select('table_name.user_id','table_name.post_id','table_name.name')
->groupBy('table_name.user_id')
->get();

This is how I'd do it. This way it's cleaner and working for me.

$img = DB::table('table_name')->select('user_id','post_id','name')
                              ->groupBy('post_id')
                              ->get();
$img = DB::table('table_name')
 ->select('user_id','post_id','name')
 ->groupBy('post_id')
 ->get();

If you're running into this SQLSTATE[42000]: Syntax error or access violation: 1055 error be sure to check that the groupBy parameter is a valid column on the table