All Projects β†’ sprocketbox β†’ eloquence

sprocketbox / eloquence

Licence: MIT license
Eloquence provides a cache on top of Eloquent that prevents multiple models being created for a single database row using the Identity Map design pattern.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to eloquence

laravel-quasar
β°πŸ“Šβœ¨Laravel Time Series - Provides an API to create and maintain data projections (statistics, aggregates, etc.) from your Eloquent models, and convert them to time series.
Stars: ✭ 78 (+333.33%)
Mutual labels:  eloquent, eloquent-models, eloquent-orm
Laravel Cascade Soft Deletes
Cascading deletes for Eloquent models that implement soft deletes
Stars: ✭ 498 (+2666.67%)
Mutual labels:  eloquent, eloquent-models
Laravel Deletable
πŸ‘Ύ Gracefully restrict deletion of Laravel Eloquent models
Stars: ✭ 137 (+661.11%)
Mutual labels:  eloquent, eloquent-models
Laravel Database Encryption
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Stars: ✭ 238 (+1222.22%)
Mutual labels:  eloquent, eloquent-models
Eloquent Hashids
On-the-fly hashids for Laravel Eloquent models. (🍰 Easy & ⚑ Fast)
Stars: ✭ 196 (+988.89%)
Mutual labels:  eloquent, eloquent-models
encryptable
Laravel package for persisting encrypted Model properties, providing decryption when accessed.
Stars: ✭ 26 (+44.44%)
Mutual labels:  eloquent, eloquent-models
Eloquentfilter
An Eloquent Way To Filter Laravel Models And Their Relationships
Stars: ✭ 1,113 (+6083.33%)
Mutual labels:  eloquent, eloquent-models
Laravel Transactional Model Events
Add eloquent model events fired after a transaction is committed or rolled back
Stars: ✭ 52 (+188.89%)
Mutual labels:  eloquent, eloquent-models
Laravel Lucene Search
Laravel 4.2, 5.* package for full-text search over Eloquent models based on ZF2 Lucene.
Stars: ✭ 75 (+316.67%)
Mutual labels:  eloquent, eloquent-models
Laravel Schedulable
Schedule and unschedule eloquent models elegantly without cron jobs
Stars: ✭ 78 (+333.33%)
Mutual labels:  eloquent, eloquent-models
Eloquent Approval
Approval process for Laravel Eloquent models
Stars: ✭ 79 (+338.89%)
Mutual labels:  eloquent, eloquent-models
inertiajs-tables-laravel-query-builder
Inertia.js Tables for Laravel Query Builder
Stars: ✭ 391 (+2072.22%)
Mutual labels:  eloquent, eloquent-models
Eloquent Relativity
Allows you to decouple your eloquent models from one another.
Stars: ✭ 112 (+522.22%)
Mutual labels:  eloquent, eloquent-models
laravel-autonumber
Laravel package to create autonumber for Eloquent model
Stars: ✭ 26 (+44.44%)
Mutual labels:  eloquent, eloquent-models
laravel-nestedupdater
Package for allowing updating of nested Eloquent model relations using a single nested data array.
Stars: ✭ 19 (+5.56%)
Mutual labels:  eloquent, eloquent-models
Elasticquent
Maps Laravel Eloquent models to Elasticsearch types
Stars: ✭ 1,172 (+6411.11%)
Mutual labels:  eloquent, eloquent-models
Laravel Nullable Fields
Handles saving empty fields as null for Eloquent models
Stars: ✭ 88 (+388.89%)
Mutual labels:  eloquent, eloquent-models
Searchable
Search/filter functionality for Laravel's Eloquent models
Stars: ✭ 113 (+527.78%)
Mutual labels:  eloquent, eloquent-models
Pinatra
A PHP copy of Sinatra: a DSL for quickly creating web applications in PHP with minimal effort.
Stars: ✭ 151 (+738.89%)
Mutual labels:  eloquent
Coloquent
Javascript/Typescript library mapping objects and their interrelations to JSON API, with a clean, fluent ActiveRecord-like (e.g. similar to Laravel's Eloquent) syntax for creating, retrieving, updating and deleting model objects.
Stars: ✭ 149 (+727.78%)
Mutual labels:  eloquent

Due to a conflict in naming, this package has been renamed as eloquent-identity to avoid confusion.

Eloquence

Latest Stable Version Latest Unstable Version License Scrutinizer Code Quality

Eloquence provides a cache on top of Eloquent that prevents multiple models being created for a single database row using the Identity Map design pattern (P of EAA Wikipedia).

Table of Contents

Installing

To install this package simply run the following command.

composer require sprocketbox/eloquence

This package uses auto-discovery to register the service provider but if you'd rather do it manually, the service provider is:

Sprocketbox\Eloquence\ServiceProvider

There is no configuration required.

Usage

To make use of Eloquence on your models, add the following trait.

Sprocketbox\Eloquence\Concerns\MapsIdentity

Finding

Any calls to find(), findOrFail() or findOrNew() on a model that uses this trait, will skip the query if a model has already been created using the provided id.

Calls to findMany() will skip any ids that have already been used, only querying ones that are not present in the cache.

The query is only skipped if there are no where clauses, joins or having statements.

If you wish to force the query, you can call refreshIdentityMap() on the query builder instance. If you wish to skip the query on a builder instance where refreshIdentityMap() has been called, you can call useIdentityMap().

Hydrating

When the query builder attempts to create a new instance of a model using this trait, with a key that matches an already existing instance of the model, the existing instance will be used.

If the model is using timestamps, and the returned attributes are newer, the attributes on the existing instance will be updated, but will retain any changes you'd previously made.

BelongsTo

If a belongs to relationship is loaded (not belongs to many) without constraints and without refreshIdentityMap() being called, the query will skip any model instances that already exist.

Flushing

If you wish to flush the cached models, call flushIdentities() on an instance of IdentityManager, or on the Eloquence facade.

How

The IdentityManager stores an array containing all existing model instances and their identity.

The identities for models are stored as string, created using the following class.

Sprocketbox\Eloquence\ModelIdentity

This contains a key, the model class name, and the connection name. The string version of these looks like so:

connection:class:key

Why

It's very easy to end up with multiple versions of the same model, meaning that updates on one aren't persisted to others.

Eloquence was created to reduce the number of models created, help limit unnecessary queries, and allow for consistent model interaction. It doesn't matter where in your code you're dealing with user 1, any changes made during a request will persist across all instances.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].