PHP code example of martinpetricko / filament-restore-or-create

1. Go to this page and download the library: Download martinpetricko/filament-restore-or-create library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

martinpetricko / filament-restore-or-create example snippets


use MartinPetricko\FilamentRestoreOrCreate\Concerns\CreateRecord\CheckDeleted;

class CreateUser extends CreateRecord
{
    use CheckDeleted;

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

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

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

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

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

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();
}

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

    protected function beforeCreate(): void
    {
        $this->checkDeletedBeforeCreate();
        
        // Your custom logic
    }
}
bash
php artisan vendor:publish --tag="filament-restore-or-create-translations"