F
Filament11mo ago
torriv

getTableRecordKey(): Return value must be of type string, null

I suddenly get this error: Filament\Resources\Pages\ListRecords::getTableRecordKey(): Return value must be of type string, null returned In V2 I used to solve it by having this:
public function getTableRecordKey(Model $record): string
{
return uniqid();
}
public function getTableRecordKey(Model $record): string
{
return uniqid();
}
This doesn't seem to work anymore. this error came today after updating to the latest version. the table query:
return $table
->query(
Timesheet::query()
->select(DB::raw('DATE(DATE_FORMAT(fra_dato, \'%Y-%m-01\')) AS month, SUM(totalt) AS Totalt'))
->groupBy(DB::raw("DATE(DATE_FORMAT(fra_dato, '%Y-%m-01'))"))
->whereBetween(
'fra_dato',
[
Carbon::parse('first day of January')->format('Y-m-d H:i:s'),
Carbon::now()->endOfYear(),
]
)
->where('unavailable', 0)
)
return $table
->query(
Timesheet::query()
->select(DB::raw('DATE(DATE_FORMAT(fra_dato, \'%Y-%m-01\')) AS month, SUM(totalt) AS Totalt'))
->groupBy(DB::raw("DATE(DATE_FORMAT(fra_dato, '%Y-%m-01'))"))
->whereBetween(
'fra_dato',
[
Carbon::parse('first day of January')->format('Y-m-d H:i:s'),
Carbon::now()->endOfYear(),
]
)
->where('unavailable', 0)
)
Solution:
well... the reason for the error was because of two entries in my DB that had no ID... my bad!
Jump to solution
14 Replies
torriv
torriv11mo ago
anyone have any solution? 🙂
Dennis Koch
Dennis Koch11mo ago
Not sure why it complains about null return? Uniquid() shouldn’t be null right?
LeandroFerreira
LeandroFerreira11mo ago
did you add in the ListPage file?
torriv
torriv11mo ago
i saw that it said pages\ListRecords, so i moved the code into ListTimesheets.php, but then i get this error suddenly:
Missing required parameter for [Route: filament.admin.resources.timelister.edit] [URI: admin/timelister/{record}/edit] [Missing parameter: record].
Missing required parameter for [Route: filament.admin.resources.timelister.edit] [URI: admin/timelister/{record}/edit] [Missing parameter: record].
LeandroFerreira
LeandroFerreira11mo ago
Do you have 'edit' route in the getPages() method? If you are using a read-only table, you should remove the edit route/action
torriv
torriv11mo ago
by commenting out
'edit' => Pages\EditTimesheet::route('/{record}/edit'),
'edit' => Pages\EditTimesheet::route('/{record}/edit'),
it works. but I need to be able to edit
LeandroFerreira
LeandroFerreira11mo ago
Curious to know how you will do this, considering you are using an auto UUID...
torriv
torriv11mo ago
well, before today, when i updated to the latest release, i didn't have to overwrite the getTableRecordKey(). everything was working. and i just found that solution to overwrite the getTableRecordKey() function. haven't needed to do that before. (i tried to revert the update, but the error still excisists). i'll try to look for other changes and see if i find anything that has changed from working to not working verision of my app.
Dennis Koch
Dennis Koch11mo ago
Not sure how it worked. How did it know which record to edit when there was no key? 🤔
LeandroFerreira
LeandroFerreira11mo ago
I don't believe the issue is related to the Filament version, as the query you posted with an aggregation (sum) wouldn't work in even Filament v2. Unless you were employing a workaround similar to the one found here: https://v2.filamentphp.com/tricks/using-tables-with-aggregated-grouped-data
Filament
Using tables with aggregated / grouped data by Simon Bühler - Trick...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
torriv
torriv11mo ago
i agree. and it isn't that query that causes it anyways. when i commenting out the widget, the error is still there. so it has to be somewhere else. I'm not doing anything with the query on the resource page.
LeandroFerreira
LeandroFerreira11mo ago
So, why are you doing this? ->select(DB::raw('DATE(DATE_FORMAT(fra_dato, \'%Y-%m-01\')) AS month, SUM(totalt) AS Totalt'))... ?
torriv
torriv11mo ago
that's from the widget. i first thought it was the widget causing the problem. but when commenting out the widget, the error is still there.
Solution
torriv
torriv11mo ago
well... the reason for the error was because of two entries in my DB that had no ID... my bad!