Custom text columns, calculated values, sum of related table values.

Hi,
I have:

Model: Booking
public function deals(): hasMany
{
    return $this->hasMany(Deal::class);
}


Model: Deal
public function booking(): belongsTo
{
    return $this->belongsTo(Booking::class);
}


My booking view shows this table (part of it).

I have some questions, please read the comments.

Tables\Columns\ColumnGroup::make('Deals', [

    //Works as wanted, shows how many deals I have per booking.
    Tables\Columns\TextColumn::make('deals_count')
        ->counts('deals'),

    //Works as wanted, shows the price of each deal per booking
    Tables\Columns\TextColumn::make('deals.price')
        ->label('Each Deal Price')
        ->listWithLineBreaks()
        ->money('gbp', divideBy: 100),

    //How can I calculate the sum of all deals?
    Tables\Columns\TextColumn::make('???')
        ->label('All Deals Prices Sum')
        -???,

    //Works as wanted (different VAT values are stored in the DB)
    Tables\Columns\TextColumn::make('vat')
        ->label('VAT')
        ->suffix('%'),

    //How can I calculate the sum of all deals plus the value of the VAT?
    Tables\Columns\TextColumn::make('???')
        ->label('All Deals Prices Sum + VAT')
        ???,

])


Please, any advice is much appreciated,
Thank you,
Pablo
Was this page helpful?