PHPackages                             litepie/database - 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. litepie/database

ActiveLibrary[Database &amp; ORM](/categories/database)

litepie/database
================

Advanced Laravel Database package with enhanced Eloquent traits, scopes, casts, and utilities for modern Laravel applications

v1.0.5(5mo ago)0292MITPHPPHP ^8.2|^8.3

Since Aug 23Pushed 5mo agoCompare

[ Source](https://github.com/Litepie/Database)[ Packagist](https://packagist.org/packages/litepie/database)[ Docs](https://github.com/litepie/database)[ Fund](https://paypal.me/renfostech)[ Fund](https://renfos.com/sponsor)[ RSS](/packages/litepie-database/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (11)Versions (7)Used By (2)

Litepie Database Package
========================

[](#litepie-database-package)

[![Latest Stable Version](https://camo.githubusercontent.com/08f430e9b9f558575b41bd4932b0e99be5cac890f2b703d7a8381adcc6f90c7c/68747470733a2f2f706f7365722e707567782e6f72672f6c6974657069652f64617461626173652f762f737461626c65)](https://packagist.org/packages/litepie/database)[![Total Downloads](https://camo.githubusercontent.com/36d88d5d1c047bfc4d78124d192ddf82d84bbfc103b86bc768a66ed4ccc9646b/68747470733a2f2f706f7365722e707567782e6f72672f6c6974657069652f64617461626173652f646f776e6c6f616473)](https://packagist.org/packages/litepie/database)[![License](https://camo.githubusercontent.com/ba9923058477023378d3517e19d798d630561b58c2960313084e8c865cab4e0b/68747470733a2f2f706f7365722e707567782e6f72672f6c6974657069652f64617461626173652f6c6963656e7365)](https://packagist.org/packages/litepie/database)

An advanced Laravel database package that provides enhanced Eloquent traits, scopes, casts, and utilities for modern Laravel applications. This package extends Laravel's Eloquent ORM with powerful features for archiving, searching, caching, slugs, and more.

Features
--------

[](#features)

### Core Traits (14 Available)

[](#core-traits-14-available)

- 📦 **Versionable**: Track model version history with rollback capability
- 🏷️ **Metable**: Flexible key-value metadata storage (WordPress-style)
- 🌍 **Translatable**: Multi-language content support with automatic locale handling
- 🔍 **Searchable**: Powerful search with multiple strategies (full-text, fuzzy, weighted, boolean)
- ⚡ **Cacheable**: Smart caching with tags, invalidation, and warm-up strategies
- 🔗 **Sluggable**: Advanced slug generation with multiple strategies
- 📄 **Paginatable**: Cursor, seek, window, and cached pagination for large datasets
- 📊 **Aggregatable**: Statistical analysis and reporting (23 analytics methods)
- 🗃️ **Archivable**: Soft archiving with reasons and user tracking
- 📤 **Exportable**: Export data to CSV, Excel, JSON formats
- 📥 **Importable**: Import and validate data from CSV
- 🔢 **Sortable**: Manual ordering and drag-drop support
- 📋 **Batchable**: Efficient bulk operations for large datasets
- 📏 **Measurable**: Query performance monitoring and optimization

### Additional Features

[](#additional-features)

- 💰 **Money Handling**: Robust money casting with multi-currency support
- 📊 **JSON Enhancement**: Advanced JSON casting with schema validation
- 🔧 **Custom Macros**: Dynamic model macro system for extending Eloquent
- 🎯 **Smart Scopes**: Advanced query scopes for complex filtering

### 🤖 AI-Ready Package

[](#-ai-ready-package)

This package is fully optimized for AI-assisted development! Use with GitHub Copilot, Cursor AI, ChatGPT, Claude, and other AI coding tools. See [AI Integration Guide](.ai/README.md) for details.

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

[](#installation)

Install the package via Composer:

```
composer require litepie/database
```

Requirements
------------

[](#requirements)

- PHP 8.2, 8.3, or 8.4
- Laravel 10.x, 11.x, or 12.x
- MySQL 5.7+, PostgreSQL 10+, or SQLite 3.8+

### Laravel Auto-Discovery

[](#laravel-auto-discovery)

The package will automatically register its service provider and facades through Laravel's package auto-discovery feature.

### Manual Registration (Optional)

[](#manual-registration-optional)

If you need to manually register the service provider, add it to your `config/app.php`:

```
'providers' => [
    // ...
    Litepie\Database\DatabaseServiceProvider::class,
],

'aliases' => [
    // ...
    'ModelMacro' => Litepie\Database\Facades\ModelMacro::class,
],
```

### Publishing Configuration

[](#publishing-configuration)

Optionally, publish the configuration file:

```
php artisan vendor:publish --tag=litepie-database-config
```

Quick Start for AI Tools
------------------------

[](#quick-start-for-ai-tools)

Ask your AI assistant natural questions like:

```
"How do I track changes to my Post model?"
"I need custom product attributes in Laravel"
"Show me how to add multi-language support"
"How do I create an analytics dashboard?"

```

Your AI will reference this package's comprehensive documentation in the `.ai/` directory to provide accurate, working code.

### Common Use Cases

[](#common-use-cases)

#### CMS / Blog

[](#cms--blog)

```
class Post extends Model {
    use Versionable, Translatable, Sluggable, Searchable, Cacheable;
    protected array $translatable = ['title', 'content'];
}
```

#### E-commerce Product

[](#e-commerce-product)

```
class Product extends Model {
    use Translatable, Metable, Searchable, Cacheable, Sluggable;
    protected array $translatable = ['name', 'description'];
}
```

#### Analytics Dashboard

[](#analytics-dashboard)

```
class Order extends Model {
    use Aggregatable, Cacheable, Exportable;
}
```

#### User Preferences

[](#user-preferences)

```
class User extends Model {
    use Metable, Versionable;
}
```

For complete examples and AI integration details, see:

- 📖 [AI Integration Guide](.ai/README.md)
- 🚀 [Quick Reference](.ai/quick-reference.md)
- 💻 [Code Examples](.ai/code-examples.md)
- 📝 [AI Prompts](.ai/ai-prompts.md)

Usage
-----

[](#usage)

### 1. Version Control (Versionable Trait)

[](#1-version-control-versionable-trait)

Track complete version history with rollback capability.

```
use Litepie\Database\Traits\Versionable;

class Post extends Model
{
    use Versionable;

    protected int $maxVersions = 20;
    protected array $versionableExclude = ['views', 'updated_at'];
}

// Usage
$post->createVersion('Major update', auth()->user());
$post->rollbackToVersion(5);
$history = $post->getVersionHistory();
$comparison = $post->compareVersions(1, 5);
```

See [examples/versionable\_example.php](examples/versionable_example.php) for 20 detailed examples.

### 2. Custom Metadata (Metable Trait)

[](#2-custom-metadata-metable-trait)

WordPress-style flexible key-value storage.

```
use Litepie\Database\Traits\Metable;

class Product extends Model
{
    use Metable;
}

// Usage
$product->setMeta('featured', true);
$product->setMeta('warranty_months', 24);
$featured = Product::whereMeta('featured', true)->get();
$product->incrementMeta('view_count');
```

See [examples/metable\_example.php](examples/metable_example.php) for 20 detailed examples.

### 3. Multi-Language (Translatable Trait)

[](#3-multi-language-translatable-trait)

Support multiple languages with automatic locale handling.

```
use Litepie\Database\Traits\Translatable;

class Post extends Model
{
    use Translatable;

    protected array $translatable = ['title', 'content'];
}

// Usage
$post->translate('es', ['title' => 'Título', 'content' => 'Contenido']);
$post->setLocale('es');
echo $post->title; // Returns Spanish translation
$completeness = $post->getTranslationCompleteness('es'); // 100%
```

See [examples/translatable\_example.php](examples/translatable_example.php) for 20 detailed examples.

### 4. Analytics &amp; Reporting (Aggregatable Trait)

[](#4-analytics--reporting-aggregatable-trait)

23 powerful methods for statistics and reporting.

```
use Litepie\Database\Traits\Aggregatable;

class Order extends Model
{
    use Aggregatable;
}

// Usage
$stats = Order::aggregate(['sum' => 'total', 'avg' => 'total']);
$trend = Order::trend('created_at', 'month', 'revenue', 'sum');
$growth = Order::growthRate('total', 'month', 6);
$yoy = Order::yearOverYear('sales', 'sum');
$comparison = Order::compareWithPreviousPeriod('total', 'sum', 'month');
```

See [examples/aggregatable\_example.php](examples/aggregatable_example.php) for 31 detailed examples.

### 5. Archivable Trait

[](#5-archivable-trait)

The enhanced Archivable trait provides soft archiving functionality with additional features like reason tracking and user auditing.

#### Basic Usage

[](#basic-usage)

```
