Question about tables

I have the following table. But I would like the backup_date to appear as a column and show the result of each server on each date. It's possible?
public function table(Table $table): Table
{
return $table
->query(Backup::query()
->select(
'backups.backup_date',
'backups.backup_status',
'backups.observations',
'servers.name as server_name'
)
->join('servers', 'backups.server_id', '=', 'servers.id'))
->columns([
Tables\Columns\TextColumn::make('server_name')
->sortable(),
Tables\Columns\TextColumn::make('backup_date'),
Tables\Columns\TextColumn::make('backup_status'),
])
->defaultSort('backup_date')
->paginated(false);
}
public function table(Table $table): Table
{
return $table
->query(Backup::query()
->select(
'backups.backup_date',
'backups.backup_status',
'backups.observations',
'servers.name as server_name'
)
->join('servers', 'backups.server_id', '=', 'servers.id'))
->columns([
Tables\Columns\TextColumn::make('server_name')
->sortable(),
Tables\Columns\TextColumn::make('backup_date'),
Tables\Columns\TextColumn::make('backup_status'),
])
->defaultSort('backup_date')
->paginated(false);
}
7 Replies
Dennis Koch
Dennis Koch3mo ago
And what is the issue? Btw. you could also just use a server() relationship on the backup and load that one.
H.Bilbao
H.Bilbao3mo ago
I may have explained wrong or I may not be doing something right. This is just a hobby for me.. According to the attached photo, the photo above is what I currently have and the photo below is where I want to go. ignore the colors in the table below
No description
Dennis Koch
Dennis Koch3mo ago
Sure. If you have the same data for every server: It's a for-loop to create the columns. Then use ->getStateUSing() to get the correct backup status for each column
H.Bilbao
H.Bilbao3mo ago
Thanks Dennis. I have reached this point where something is missing me because the result is not correct. Can someone help me see where the error could be? I see the same result on all servers for the day https://gist.github.com/mendizalea/bb103f20f39f7265c29cd6e7cba5c0d6
Gist
gist:bb103f20f39f7265c29cd6e7cba5c0d6
GitHub Gist: instantly share code, notes, and snippets.
Dennis Koch
Dennis Koch3mo ago
Not sure why you are looping over the servers? They already are the rows. You just needs to loop over backups. Like "Last 5 backups"
H.Bilbao
H.Bilbao3mo ago
Thank you for everything but I have reached a point of blockage, I can't find the solution. I'm going to try to redo everything I have, because I have gone through the shared code several times but I can't quite see the result.
H.Bilbao
H.Bilbao3mo ago
Finally, once writing everything again I have achieved the necessary result. How could I modify the $month variable from the filter? https://gist.github.com/mendizalea/74a647bc0a92aa702843fbc6678ca2d6
Gist
ReportBackups.php
GitHub Gist: instantly share code, notes, and snippets.