Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Filament Restore Or Create Laravel Package

martinpetricko/filament-restore-or-create

View on GitHub
Deep Wiki
Context7

Filament Restore or Create

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Restore or Create is a FilamentPHP plugin that helps prevent duplicate records by detecting and restoring soft-deleted models when similar data is submitted via a create form.

Features

  • Detects similar soft-deleted records before creating a new one.
  • Displays a modal with details and an option to restore the deleted record.
  • Fully customizable detection, display, and behavior logic.

Installation

Install via Composer:

composer require martinpetricko/filament-restore-or-create

Optionally, publish the translation files:

php artisan vendor:publish --tag="filament-restore-or-create-translations"

Usage

Add CheckDeleted trait to your resource's CreateRecord page:

use MartinPetricko\FilamentRestoreOrCreate\Concerns\CreateRecord\CheckDeleted;

class CreateUser extends CreateRecord
{
    use CheckDeleted;

    protected static string $resource = UserResource::class;
}

Customization

Attributes to check

Define which fields should be used to detect similar deleted records:

protected function checkDeletedAttributes(): array
{
    return ['name', 'email', 'phone'];
}

Custom Query Logic

Override the default query to define your own matching logic:

protected function checkDeletedModel(array $data): ?Model
{
    return static::getResource()::getEloquentQuery()
        ->whereLike('name', '%' . $data['name'] . '%')
        ->onlyTrashed()
        ->latest()
        ->first();
}

Modal Display Fields

Choose which attributes to show in the confirmation modal:

protected function showDeletedAttributes(): ?array
{
    return ['name', 'email', 'phone', 'address', 'deleted_at'];
}

Restore Notification

Customize the notification shown after a record is restored:

protected function getRestoredNotification(): ?Notification
{
    return Notification::make()
        ->success()
        ->title('Restored');
}

Redirect After Restore

Control where the user is redirected after restoring:

protected function getRestoreRedirectUrl(Model $record): string
{
    /** @var class-string<Resource> $resource */
    $resource = static::getResource();

    if ($resource::hasPage('edit') && $resource::canEdit($record)) {
        return $resource::getUrl('edit', ['record' => $record]);
    }

    return $resource::getUrl();
}

Advanced Integration

If you override beforeCreate, ensure the restore behavior is still called:

class CreateUser extends CreateRecord
{
    use CheckDeleted {
        beforeCreate as checkDeletedBeforeCreate;
    }

    protected function beforeCreate(): void
    {
        $this->checkDeletedBeforeCreate();
        
        // Your custom logic
    }
}

Testing

composer test

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium