2

I am trying to get the data using groupBy on type field from my transaction table. I am using this query

DB::table($this->table)
    ->select()
    ->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())
    ->groupBy('type')
    ->get();

But it is not giving the complete records. There are more than 10 records in my table. But it is giving me only two. One for type=1 and another for type=2. It is selecting only on record from each type. I am expecting that i will get all the transactions based on condition grouped in two result set. Anyone know why it is happening?

Sohel0415
  • 9,523
  • 21
  • 30
RAUSHAN KUMAR
  • 5,846
  • 4
  • 34
  • 70

2 Answers2

5

Try to call Collection groupBy instead. Just put groupBy after get(). It should work.

DB::table($this->table)
    ->select()
    ->whereRaw($where['rawQuery'], isset($where['bindParams']) ? $where['bindParams'] : array())
    ->get()
    ->groupBy('type');
Laerte
  • 7,013
  • 3
  • 32
  • 50
-1

Faq::where('type','host')->get()->groupBy('category');

kush
  • 595
  • 5
  • 7