mardi 1 août 2017

Laravel Eloquent GroupBy statement

have this table and i'm tring to achive a multiple groupBy and distinct troug Laravel with a sum of duration. Basically i need to find in table multiple ids passed from controller and then if windows, method and type are the same, sum the duration value.

Here is table structure

ids| windows | method | duration | type |


1 | 2 | 3 | 5 | 2 |


2 | 2 | 3 | 5 | 2 |


3 | 2 | 3 | 5 | 2 |

and here is the statement that i try to use:

$tickets_g = \App\Models\Ticked::whereIn('id', $tickets)->select('categoria', 'tipologia', 'priority', 'durata')->distinct()->GroupBy('categoria')->GroupBy('tipologia')->GroupBy('priority')->sum('durata')->get();

Can someone help me to figure out?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire