### Install Filament Restore or Create Plugin Source: https://github.com/martinpetricko/filament-restore-or-create/blob/main/README.md Install the plugin using Composer. This is the initial setup step. ```bash composer require martinpetricko/filament-restore-or-create ``` -------------------------------- ### Install Filament Restore or Create Package Source: https://context7.com/martinpetricko/filament-restore-or-create/llms.txt Install the package via Composer and optionally publish translation files using Artisan. ```bash composer require martinpetricko/filament-restore-or-create php artisan vendor:publish --tag="filament-restore-or-create-translations" ``` -------------------------------- ### Customize English Translations Source: https://context7.com/martinpetricko/filament-restore-or-create/llms.txt Example of a translation file for the 'actions' module in English. Customize modal headings, descriptions, submit buttons, and notification titles. ```php [ 'modal_heading' => 'Restore deleted record?', 'modal_description'=> 'We found a deleted record that is similar to the one you are trying to create. Would you like to restore it?', 'submit' => 'Restore', 'notifications' => [ 'success' => [ 'title' => 'Restored', ], ], ], ]; ``` -------------------------------- ### Basic Setup with CheckDeleted Trait Source: https://context7.com/martinpetricko/filament-restore-or-create/llms.txt Add the `CheckDeleted` trait to a Filament `CreateRecord` page to enable duplicate detection and restore functionality. This automatically checks for soft-deleted records matching the resource's title attribute upon form submission. ```php checkDeletedBeforeCreate(); // Your custom logic } } ``` -------------------------------- ### Configure Standalone CheckDeletedAction Source: https://context7.com/martinpetricko/filament-restore-or-create/llms.txt Configure the `CheckDeletedAction` directly by overriding `checkDeletedAction()`. This allows customization of the modal's schema, redirect URL, notification, and labels. ```php schema($this->getRestoreSchema()) // Info list schema shown in modal ->restoreRedirectUrl(fn (Model $record) => $this->getRestoreRedirectUrl($record)) ->successNotification( Notification::make()->success()->title('Restored!') ) ->modalHeading('Duplicate Found') ->modalDescription('A deleted record with similar details was found. Restore it?') ->modalSubmitActionLabel('Yes, Restore'); } } ``` -------------------------------- ### Control Modal Display Fields with showDeletedAttributes() Source: https://context7.com/martinpetricko/filament-restore-or-create/llms.txt Override the `showDeletedAttributes()` method to specify which model attributes are displayed in the restore confirmation modal. Returning `null` will display all attributes. ```php $resource */ $resource = static::getResource(); if ($resource::hasPage('edit') && $resource::canEdit($record)) { return $resource::getUrl('edit', ['record' => $record]); } return $resource::getUrl(); } ``` -------------------------------- ### Specify Attributes for Confirmation Modal Source: https://github.com/martinpetricko/filament-restore-or-create/blob/main/README.md Control which attributes are displayed in the confirmation modal when a potential duplicate is found by overriding `showDeletedAttributes`. ```php protected function showDeletedAttributes(): ?array { return ['name', 'email', 'phone', 'address', 'deleted_at']; } ``` -------------------------------- ### Preserve `beforeCreate` Override with Trait Aliasing Source: https://context7.com/martinpetricko/filament-restore-or-create/llms.txt When overriding `beforeCreate()`, use trait aliasing to ensure the plugin's detection logic runs alongside your custom code. Call the aliased trait method first. ```php checkDeletedBeforeCreate(); // Your own pre-creation logic runs after. $this->data['created_by'] = auth()->id(); $this->data['ip_address'] = request()->ip(); } } ``` -------------------------------- ### Custom Query Logic for Deleted Models Source: https://github.com/martinpetricko/filament-restore-or-create/blob/main/README.md Override the `checkDeletedModel` method to define custom logic for finding matching soft-deleted records. ```php protected function checkDeletedModel(array $data): ?Model { return static::getResource()::getEloquentQuery() ->whereLike('name', '%' . $data['name'] . '%') ->onlyTrashed() ->latest() ->first(); } ``` -------------------------------- ### Configure Match Fields with checkDeletedAttributes() Source: https://context7.com/martinpetricko/filament-restore-or-create/llms.txt Override the `checkDeletedAttributes()` method to specify which form fields are used for querying soft-deleted records. By default, it uses the resource's title attribute. ```php success() ->title('Restored'); } ``` -------------------------------- ### Custom Query Logic with checkDeletedModel() Source: https://context7.com/martinpetricko/filament-restore-or-create/llms.txt Override the `checkDeletedModel()` method to implement custom Eloquent query logic for matching soft-deleted records, such as using LIKE queries or additional scopes. This method should return the most recently deleted match or null. ```php $data Submitted form data. */ protected function checkDeletedModel(array $data): ?Model { // Use a LIKE query on name instead of exact match. // Returns the most recently deleted match, or null if none found. return UserResource::getEloquentQuery() ->whereLike('name', '%' . $data['name'] . '%') ->onlyTrashed() ->latest('deleted_at') ->first(); } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.