To prevent Statamic from deleting form submissions on every deployment, you need to ensure that the storage location for form submissions is not overwritten during the deployment process. Here are a few steps you can take to achieve this:
-
Use a Persistent Storage Location: By default, Statamic stores form submissions in the
storage/formsdirectory. You can configure your deployment process to exclude this directory from being overwritten. -
Configure Deployment Tool: If you are using a deployment tool like Laravel Forge, Envoyer, or any CI/CD pipeline, you can configure it to preserve the
storage/formsdirectory. For example, in Laravel Forge, you can add a deployment hook to create a symlink to a persistent storage location. -
Use a Database for Form Submissions: Another approach is to store form submissions in a database instead of the file system. This way, the submissions are not affected by file system changes during deployment.
Here is an example of how you can configure Statamic to use a database for form submissions:
-
Install the Database Addon: First, you need to install the Statamic Database addon. You can do this via Composer:
composer require statamic/eloquent-driver -
Configure the Addon: Next, you need to configure Statamic to use the database for form submissions. Update your
config/statamic/eloquent-driver.phpconfiguration file to include the forms driver:'forms' => [ 'driver' => 'eloquent', ], -
Run Migrations: Run the necessary migrations to create the database tables for form submissions:
php artisan migrate -
Update Form Configuration: Finally, update your form configuration to use the database driver. In your form YAML file, set the
storeoption todatabase:title: Contact Form store: database fields: - handle: name field: type: text display: Name - handle: email field: type: text display: Email - handle: message field: type: textarea display: Message
By following these steps, you can ensure that form submissions are stored in a database, which will not be affected by file system changes during deployment. This will prevent the loss of form submissions on every deployment.
If you prefer to stick with file-based storage, make sure to configure your deployment process to preserve the storage/forms directory.
I hope this helps! If you have any further questions, feel free to ask.