1

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,065
  • 20
  • 28
RAUSHAN KUMAR
  • 5,595
  • 4
  • 31
  • 65

2 Answers2

3

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
  • 6,773
  • 3
  • 31
  • 49
-1

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

kush
  • 439
  • 4
  • 7