Error on Delete action

I get an error when deleting a record from a resource. The recording is deleted, but this error still appears. At the same time, if you delete through the table using bulk action, then there is no such error. Error: Call to a member function getKey() on null
No description
Solution:
Working fine with custom action and query like DB::table(‘tags’)->where(‘id’, $record->id)->delete();
Jump to solution
12 Replies
toeknee
toeknee10mo ago
Do you have a delete action?
mar5hall
mar5hallOP10mo ago
Yes. Default Filament delete action generated for resource
toeknee
toeknee10mo ago
Sounds like you must have forgein keys or similar and it's trying to remove it can can't get the id essentially
mar5hall
mar5hallOP10mo ago
The record is deleted successfully, judging by the logs. But at the same time I get this error.
No description
toeknee
toeknee10mo ago
So you have a tags relationship? Do you have a belongsToMany for tags opposed to hasMany ?
mar5hall
mar5hallOP10mo ago
No description
toeknee
toeknee10mo ago
That's likely why, I could be wrong but a record shouldn't belong to many. It should have many tags, by belonging to many tags it'll try and update/delete them.
mar5hall
mar5hallOP10mo ago
If i use hasMany i can`t use select relationships
No description
mar5hall
mar5hallOP10mo ago
And why then if you delete through the list using bulk action, there is no error?
toeknee
toeknee10mo ago
I am unsure, are you using a custom tags model? I was assuming you were using spatie tags
mar5hall
mar5hallOP10mo ago
Custom Any ideas?
Solution
mar5hall
mar5hall10mo ago
Working fine with custom action and query like DB::table(‘tags’)->where(‘id’, $record->id)->delete();
Want results from more Discord servers?
Add your server