I have my table data like below photo.
My expected data should be like this below photo.
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