How can calculate two columns in filament

678 Views Asked by At

Please I want calculate two columns like test_mark and exam_mark how can define the total mark in total_mark column please

Example: Sql Test_mark = 40 exam_mark =30 tolal_mark =test_mark + exam_mark

How can desply it in filament table?

1

There are 1 best solutions below

0
On BEST ANSWER

https://filamentphp.com/docs/3.x/tables/columns/getting-started#calculated-state

Sometimes you need to calculate the state of a column, instead of directly reading it from a database column.

By passing a callback function to the state() method, you can customize the returned state for that column based on the $record:

Tables\Columns\TextColumn::make('amount_including_vat')
  ->state(function (Model $record): float {
    return $record->amount * (1 + $record->vat_rate);
  })