PHPackages                             ringlesoft/db-archive - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ringlesoft/db-archive

ActiveLaravel-package[Database &amp; ORM](/categories/database)

ringlesoft/db-archive
=====================

A Laravel package for archiving old database entries automatically

0.0.2(1y ago)4553↓52.4%1MITPHPPHP &gt;=8.1

Since Mar 9Pushed 11mo ago2 watchersCompare

[ Source](https://github.com/ringlesoft/db-archive)[ Packagist](https://packagist.org/packages/ringlesoft/db-archive)[ Docs](https://ringlesoft.com/packages/db-archive)[ RSS](/packages/ringlesoft-db-archive/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (8)Versions (5)Used By (0)

Laravel DB Archive
==================

[](#laravel-db-archive)

Easily archive your Laravel database tables periodically to keep your application database lean and performant.

---

[![Latest Version on Packagist](https://camo.githubusercontent.com/76679bdaddf3274c89be89290540cd2ca30657b3932d8697d244d85529dce783/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72696e676c65736f66742f64622d617263686976652e737667)](https://packagist.org/packages/ringlesoft/db-archive)[![Total Downloads](https://camo.githubusercontent.com/648a1554f6e8ed88c784986d26961477ebcfc86173b4b17c0bc5450f31629c2a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72696e676c65736f66742f64622d617263686976652e737667)](https://packagist.org/packages/ringlesoft/db-archive)[![PHP Version Require](https://camo.githubusercontent.com/85d02c2e2d902336a36b4bb3b411312cd0a1a5b25286e58cf13ed44ea862c430/68747470733a2f2f706f7365722e707567782e6f72672f72696e676c65736f66742f64622d617263686976652f726571756972652f706870)](https://packagist.org/ringlesoft/db-archive)[![Dependents](https://camo.githubusercontent.com/2dae2a3be8e066ab29b36a7087af26db8bda192bd4e2ad909e30aec809d01a9b/68747470733a2f2f706f7365722e707567782e6f72672f72696e676c65736f66742f64622d617263686976652f646570656e64656e7473)](https://packagist.org/packages/ringlesoft/db-archive)

---

Introduction
------------

[](#introduction)

`Laravel DB Archive` is a package that provides a simple and efficient way to archive old records from your database tables in Laravel applications. It helps maintain your application's database performance by moving historical data to archive tables, while keeping your primary tables focused on recent and relevant information.

> Laravel 10.x and above

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require ringlesoft/db-archive
```

Configuration
-------------

[](#configuration)

Publish the configuration file with:

```
php artisan vendor:publish --provider="RingleSoft\DbArchive\DbArchiveServiceProvider" --tag="config"
```

### Configuration Options:

[](#configuration-options)

#### `connection`:

[](#connection)

- The database connection name to be used for creating archive tables and moving data.
- Ensure this connection is defined in your `config/database.php` file.
- I recommend using a different connection from your application's default connection.
- Defaults to `mysql_archive` and can be overridden using the `ARCHIVE_DB_CONNECTION` environment variable.

#### `settings`:

[](#settings)

- `table_prefix`:

    - Prefix to be added to the archived tables (e.g., archive\_).
    - Set to `null` for no prefix.
- `batch_size`:

    - Number of records to process in each batch during archiving.
    - Adjust this value based on your server resources and table size.
    - Defaults to 1000.
- `date_column`:

    - The database column used to determine the age of records for archiving (e.g., `created_at`, `updated_at`).
    - Defaults to `created_at`.
- `archive_older_than_days`:

    - Number of days after which records are considered old enough to be archived.
    - Records with a date in the `date_column` older than this value will be archived.
    - Defaults to `365` days .
- `conditions`:

    - An array of additional where conditions to filter records for archiving.
    - Allows for more specific criteria for selecting records to archive.
    - Defaults to an empty array `[]`.
    - Example: `[['status', 'active']]` or `[['id', '
