Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

anonymouse703's avatar

How to delete filament record if the primary key is "key" not "id"

This is my model

    protected $primaryKey = 'key';

    public $incrementing = false;

    protected $keyType = 'string';

    protected $fillable = [
        'key',
        'value',
        'scope',
        'label',
        'description',
        'type',
        'options',
        'is_readonly',
    ];

//I already add this for the delete but not working

  public function getRouteKeyName(): string
    {
        return 'key';
    }

and this the table action


Tables\Actions\DeleteAction::make(),


\\I also try this but not working

 Tables\Actions\DeleteAction::make()
                    ->requiresConfirmation()
                    ->action(function ($record) {
                        $record->delete();
                        return Redirect::route('filament.admin.resources.settings.index');
                    })
0 likes
5 replies
Sinnbeck's avatar

I dont see any reason that shouldnt work. What happens?

anonymouse703's avatar

@Sinnbeck

The case is this, when I click the confirm in delete confirmation modal it will prompt error 404 | Not Found. But after I refresh the page the record was deleted...

Sinnbeck's avatar

@anonymouse703 Can you see what url gives the 404?

Perhaps try this instead

Tables\Actions\DeleteAction::make()
->successRedirectUrl(route('filament.admin.resources.settings.index')),
EveAT's avatar

Before calling delete(), check if $record is being resolved properly:

DeleteAction::make()
    ->requiresConfirmation()
    ->action(function ($record) {
        if (!$record) {
            dd('Record not found');
        }
        $record->delete();
    })

If Filament is not resolving the record, try direct querying:

DeleteAction::make()
    ->requiresConfirmation()
    ->action(function ($record) {
        \App\Models\YourModel::where('key', $record->key)->delete();
    })
anonymouse703's avatar

@EveAT the record is deleted the only problem is when you click the confirm button in the confirmation modal it will prompt error 404 | Not Found

@sinnbeck and @eveat

I tried this the error 404 prompt is not anymore showed up but I have a log error and the logger is not triggered even if I add activity

Updated code

Error Log

[2025-02-08 05:44:27] local.INFO: error {"message":"Error deleting the record: Unable to retrieve Setting test_delete3"} 

Please or to participate in this conversation.