Download the PHP package oddvalue/filament-draft-recovery without Composer

On this page you can find all versions of the php package oddvalue/filament-draft-recovery. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package filament-draft-recovery

Filament Draft Recovery

Latest Version on Packagist PHP Support Filament Support GitHub Tests Action Status GitHub Code Style Action Status Total Downloads Coverage

Auto-save draft & crash recovery for Filament v4 and v5 create/edit pages, with swappable storage drivers. 100% test coverage, enforced in CI.

While a user edits a create or edit form, the form state is auto-saved (debounced, 2s by default). If their browser crashes, the tab closes, or the session expires, returning to the page shows a persistent notification offering to recover or discard the draft. Drafts are cleared on a successful save and expire after 7 days.

Storage drivers

Driver Where drafts live Notes
local-storage (default) The user's browser localStorage Zero server storage; drafts are plaintext on the user's machine (see Security)
database The recoverable_drafts table Drafts follow the user across devices; payloads can be encrypted at rest
laravel-drafts On the model being edited, via oddvalue/laravel-drafts Auto-saves become draft revisions of the record itself

Custom drivers can be registered with DraftRecovery::extend().

Installation

The install command publishes the config and (for the server-side drivers) the migrations. Skip running the migrations if you only use the local-storage driver.

Usage

Add the trait to a resource's create and/or edit page:

The trait injects the JavaScript via the page footer. Nothing else to wire up.

Choosing a driver

Set the default in config/filament-draft-recovery.php (or FILAMENT_DRAFT_RECOVERY_STORE):

Per panel:

Per page:

The laravel-drafts driver

Edit-page drafts are stored directly on the model being edited via laravel-drafts' first-class auto draft feature. Requirements: the model uses the HasDrafts trait, its table has the drafts columns (including is_auto), and auto drafts are enabled (drafts.auto_drafts.enabled in laravel-drafts' config).

Custom drivers

Implement Oddvalue\FilamentDraftRecovery\Contracts\DraftStore and register it in a service provider:

Then select it like any built-in driver ('store' => 'redis', DraftRecoveryPlugin::make()->store('redis'), or protected ?string $draftStore = 'redis';).

Every method receives a DraftContext carrying the unique key (always sufficient for key/value stores) plus the page's modelClass, operation (create/edit), record (edit pages), and userId.

Save debounce

Auto-saves fire after the user stops typing for save_debounce_milliseconds (default 2000). Change the default in the config:

Or per page:

Security & sensitive data

Drafts are snapshots of raw form state. With the default local-storage driver they live in plaintext in the browser's localStorage, readable by anyone with access to the machine, the browser profile, or any script running on the page. No client-side scheme can change that, so treat local-storage as suitable for non-sensitive form data only, and point resources that handle sensitive data at a server-side driver:

Safeguards that apply out of the box:

Excluding fields

Exclusions merge from two places and apply to every driver, client- and server-side. Globally, in the config:

Per page, additive to the config:

Patterns use dot notation to reach nested state; * matches a single segment, such as repeater or builder item keys.

File uploads

When a file is selected in a FileUpload field, Livewire immediately moves the bytes to its temporary upload disk; the form state only holds a marker pointing at that temporary file. Whether a draft can bring a pending (not yet saved) upload back depends on the driver:

Files already attached to the record (edit pages) are unaffected by all of this: they are stored paths rather than temporary markers, and always survive drafting.

Limitations

Encrypting database drafts

The database driver stores payloads as plain JSON by default. To encrypt them at rest (Laravel's encrypted:array cast, using your app key):

The payload column must be a text-type column, because ciphertext does not fit a MySQL json column. The shipped migration uses longText; if you published an earlier version of the migration that used json, change the column type before enabling encryption.

Pages with their own lifecycle hooks

The trait clears drafts from afterCreate() / afterSave(). A page that defines its own version of either hook silently overrides the trait's. Call the clear method yourself:

The same applies to getFooter(): if your page overrides it, include the view from Oddvalue\FilamentDraftRecovery\Concerns\RecoversDrafts::getFooter() in your footer.

If Filament gains trait-named lifecycle hook support (filamentphp/filament PR), this caveat goes away.

How it works

Testing

Credits

Inspired by the auto-save draft & crash recovery Filament example, reworked around client-side storage and swappable drivers. Started from the Filament plugin skeleton.

License

MIT. See LICENSE.md.


All versions of filament-draft-recovery with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
filament/filament Version ^4.13|^5.8
spatie/laravel-package-tools Version ^1.15.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package oddvalue/filament-draft-recovery contains the following files

Loading the files please wait ...