This project illustrates creating fully customized forms dynamically generated from database values.
First, in the table, we only show the weeks. To achieve this, we must modify the table query. To show value in the tables column, we set it as a default value.
NOTICE: Syntax for the table is for MySQL.
app/Filament/Resources/Timesheets/Tables/TimesheetsTable.php:
public static function table(Table $table): Table{ return $table ->modifyQueryUsing(function (Builder $query) { $query->selectRaw('id, DATE_FORMAT(date, "%Y-%m-%d") as week_start') ->whereRaw('DAYOFWEEK(date) = 2') // Filter for Mondays only ->distinct() ->groupBy('week_start', 'date', 'id'); }) ->columns([ TextColumn::make('week') ->default(function (Timesheet $record) { return "Week {$record->week_start->format('Y m d')} - {$record->week_start->endOfWeek()->format('Y m d')}"; }), ]) // ...}
On the week_start
, we can use Carbon features because the Model casts it to a date.