Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Laravel
  3. Eloquence

Eloquence

MITPHP12.0.0

A Laravel package extending Eloquent with camel-cased attributes, count/sum caching, sluggable models, and readonly protection.

GitHubGitHub
575 stars56 forks0 contributors

What is Eloquence?

Eloquence is a Laravel package that extends the Eloquent ORM with additional database utilities and behaviors. It solves common development needs like automatic camel-casing of attributes, caching aggregated values (counts and sums), generating slugs, and protecting models as readonly. It integrates seamlessly as a drop-in library without altering core Laravel functionality.

Target Audience

Laravel developers building applications that require enhanced Eloquent model capabilities, such as consistent coding styles, performance optimizations via caching, or data integrity through readonly models.

Value Proposition

Developers choose Eloquence for its focused, non-intrusive enhancements to Eloquent, offering features like count/sum caching for performance, camel-casing for API consistency, and behaviors that respect domain-specific relationships—all without modifying Laravel's core.

Overview

A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.

Use Cases

Best For

  • Ensuring camelCase attribute access in JSON APIs while keeping database columns snake_case
  • Caching aggregated values like post counts per author to optimize database queries
  • Generating SEO-friendly slugs from model attributes automatically
  • Protecting critical data with readonly models to prevent accidental writes
  • Maintaining coding style consistency across Laravel applications
  • Handling model relationships with fine-grained cache configurations

Not Ideal For

  • Projects with real-time data requirements where even slight cache update delays are unacceptable
  • Teams migrating from Eloquence v10 or earlier due to breaking changes and required code refactoring
  • Applications that manage database transactions externally or at a higher architectural level, making ORM-level transaction wrapping impractical
  • Projects using PHP versions below 8.1, as Eloquence v11+ relies on PHP 8.1 attributes for configuration

Pros & Cons

Pros

Consistent API Formatting

Automatically transforms snake_case database columns to camelCase for attribute access and JSON responses, ensuring a unified coding style without altering schema migrations, as highlighted in the CamelCased traits section.

Performance Optimization via Caching

Provides count and sum caching to reduce database queries for aggregated values, such as caching post counts per author, which improves efficiency for ordering and filtering operations.

Data Integrity with Readonly Models

Allows models to be marked as readonly using the HasReadOnly trait, preventing accidental writes and ensuring data protection across domain boundaries without additional configuration.

Modern PHP 8.1 Integration

Leverages PHP 8.1 attributes for behavior configuration, offering a clean, declarative way to set up caches and other features directly on relationship methods, as seen in the CountedBy and SummedBy examples.

Cons

Breaking Changes in Major Updates

Version 11 is a complete rebuild with non-backwards-compatible changes, requiring significant code updates for upgrades, such as renaming traits and migrating cache configurations to attributes.

Transaction Dependency for Caches

The cache system strongly recommends wrapping model saves in database transactions to prevent inconsistency, adding complexity and potential points of failure if transactions are not properly managed, as warned in the cache recommendations.

Limited to PHP 8.1+ and Laravel

Requires PHP 8.1 or higher for attribute support and is tightly coupled with Laravel's Eloquent ORM, excluding projects with older PHP versions or alternative database abstractions.

Frequently Asked Questions

Quick Stats

Stars575
Forks56
Contributors0
Open Issues1
Last commit1 month ago
CreatedSince 2014

Tags

#eloquent#orm#database#caching#slug-generation#laravel#php

Built With

P
PHP
L
Laravel

Included in

Laravel13.0k
Auto-fetched 19 hours ago

Related Projects

LiveWireLiveWire

A full-stack framework for Laravel that takes the pain out of building dynamic UIs.

Stars23,556
Forks1,742
Last commit2 days ago
Debug BarDebug Bar

Debugbar for Laravel (Integrates PHP Debug Bar)

Stars19,270
Forks1,617
Last commit14 days ago
IDE HelperIDE Helper

IDE Helper for Laravel

Stars14,953
Forks1,191
Last commit14 days ago
Intervention ImageIntervention Image

PHP Image Processing

Stars14,356
Forks1,495
Last commit5 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub