Laravel Cloud is here! Zero-config managed infrastructure for Laravel apps. Deploy now.

Eloquent Serialize

anourvalar/eloquent-serialize image

Eloquent Serialize stats

Downloads
388.8K
Stars
72
Open Issues
0
Forks
5

View on GitHub →

Laravel Query Builder (Eloquent) serialization

EloquentSerialize: Eloquent Query Serialization

EloquentSerialize is a Laravel package designed to serialize and unserialize Eloquent query builders, making it easier to cache or store complex query logic in a reusable format. This package supports Laravel version 6 and above.

Key Features

  • Serialization of Query Builders: Convert your Eloquent queries into a storable format.
  • Unserialization: Reconstruct an Eloquent query builder from a serialized state.
  • Compatibility: Works with Laravel 6 and newer versions.

Installation

Install the package via Composer:

composer require anourvalar/eloquent-serialize

Usage

Serialize a Query

Convert an Eloquent query into a serialized string:

$package = \EloquentSerialize::serialize(
\App\User::query()
->with('userPhones')
->where('id', '>', '10')
->limit(20)
);

Unserialize a Query

Rebuild the original Eloquent query from a serialized string:

$builder = \EloquentSerialize::unserialize($package);
 
foreach ($builder->get() as $item) {
// Process each item
}

This package is ideal for developers looking to enhance performance by caching complex queries or needing a method to store and retrieve query logic across different parts of an application or between requests.

AnourValar photo

Telegram: @AnourValar

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Anourvalar Eloquent Serialize Related Articles

Converting Laravel Models to JSON for API Responses image

Converting Laravel Models to JSON for API Responses

Read article
A guide to Laravel's model events image

A guide to Laravel's model events

Read article
Laravel 9.35 Released image

Laravel 9.35 Released

Read article
Tutorial: Build Metabase Maps with Geocodio image

Tutorial: Build Metabase Maps with Geocodio

Read article
Serialization for Eloquent's QueryBuilder image

Serialization for Eloquent's QueryBuilder

Read article
Getting Started with Laravel Model Events image

Getting Started with Laravel Model Events

Read article
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Curotec logo

Curotec

World class Laravel experts with GenAI dev skills. LATAM-based, embedded engineers that ship fast, communicate clearly, and elevate your product. No bloat, no BS.

Curotec
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
CodeKudu logo

CodeKudu

Stand-ups, Retrospectives, and 360° Feedback for the entire team. 50% off with code LARAVELNEWS.

CodeKudu
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift