1

I have a table activites in that table it have columns id, name, description, type, user_id, created_at, updated_at from that i want to group by user_id and type and created_at want to be unique. How can i do it in laravel?

For this i did little bit of search but i didn't find any solution for this. To get unique column value some places mentioned like

$q = DB::table('activities')->distinct()->get(['created_at']);

here my question is how to get other column value?

without unique filter my current query look like

$q = DB::table('activities')
    ->select(DB::raw('user_id, type, count(*) as total'))
    ->whereNotNull('user_id');
    ->groupBy('user_id', 'type')
    ->get();
Senthurkumaran
  • 1,738
  • 2
  • 19
  • 29
  • I think you need to use two different groupBy to achieve the result you want. – Kurt Friars Jul 13 '20 at 09:18
  • can you please give me how can i achieve this with two different `groupBy`.Thanks – Senthurkumaran Jul 13 '20 at 09:27
  • 1
    Took a quick read through, https://stackoverflow.com/questions/44382353/use-distinct-with-multiple-columns-in-laravel and not confident enough to post it as an answer, just trying to be helpful. – Kurt Friars Jul 13 '20 at 09:28

0 Answers0