Group by month or week with Laravel eloquent

0

I have a project that has management of my investments, that is, it takes my daily statement and saves it in my project so that I can see how much it is yielding, in summary I have a table that these values are daily, I can already generate the information separated by day and it works perfectly (in fact it is a little more complex than this what I do but the basis is this);

But now it's getting bad to see when I get a very large date range for example 1 year, it lists every day, I wanted a way to group by month or week,

Thanks in advance for any help.

        $rows =  AtivosExtrato::select('titulo_id', DB::raw('SUM(valor_bruto_atual) AS valor'), 'data_imports.data_import as created_at')
        ->join('titulos','titulo_id', '=', 'titulos.id' )
        ->join('representantes','representante_id', '=', 'representantes.id' )
        ->join('data_imports','data_import_id', '=', 'data_imports.id' )
        ->where('user_id', Auth::user()->id) 
        ->whereBetween('data_imports.data_import', [$request->input('start_date'), $request->input('end_date')])
        ->groupBy('titulos.nome_titulo')
        ->groupBy('data_imports.data_import')
        ->orderBy('data_import')
        ->orderBy('titulos.nome_titulo')
        ->get();   

Briefly explaining what each eloquent information is:

ActiveExtrato: template where daily income information is stored;

1) join: foreign table for title names

2) join: foreign table for broker name

3) join: table that saves the date of the import and relates to the id in the asset tableExtrato, it has the function of reducing weight at the time of the searches and gaining performance.

where: limiting the user in question

WhereBetween: limiting the date range

1) groupBy: Grouping by titles

2) groupBy: grouping by import date

    
asked by anonymous 07.12.2018 / 20:01

0 answers