dimanche 24 mars 2019

Laravel Pagination group by year and month only

I want to make paginate from laravel, group by year and month only
when i used get , it work well

$data = DB::table('gallery')
        ->select(DB::raw('DATE_FORMAT(created_at, "%Y-%m") as tanggal,count(created_at) as jumlah'),'gallery.*')
        ->where('type','Foto')
        ->groupBy('tanggal')
        ->orderBy('tanggal','desc')
        ->get();

but when i use paginate , there is an error :
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'tanggal' in 'group statement' (SQL: select count(*) as aggregate from gallery where type = Foto group by tanggal)

$data = DB::table('gallery')
        ->select(DB::raw('DATE_FORMAT(created_at, "%Y-%m") as tanggal,count(created_at) as jumlah'),'gallery.*')
        ->where('type','Foto')
        ->groupBy('tanggal')
        ->orderBy('tanggal','desc')
        ->paginate(2);

Or any idea for group by just year and month laravel 5.4?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire