Repeater with relationship and group by
Hi i am trying to use repeater in a form schema. Where i would like to group by a column name.
Sample code:
Repeater::make('cash_out')
->schema([
Placeholder::make('month')
->label('')
->content(static fn ($state) => $state),
Placeholder::make('total')
->label('')
->content(static fn ($state) => $state),
])
->relationship('cash', function ($query){
return $query->select('month')
->selectRaw('SUM(amount) as total')
->groupBy('month');
})
->columns(1),
1 Reply
I am hoping that it would return a list of distinct month from month column and sum of amount. But this code only returns 1 value from month column. Example, having March, April, May will only returns May with its correctly sum of amount column.