Skip to content

laravie/serialize-queries

Repository files navigation

Serializable Laravel Query Builder

tests Latest Stable Version Total Downloads Latest Unstable Version License Coverage Status

Serialize Queries allows developer to serialize Query/Eloquent Builder to be used in Laravel Queues.

Installation

To install through composer, run the following command from terminal:

composer require "laravie/serialize-queries"

Usages

Eloquent Query Builder

Serialize

Laravie\SerializesQuery\Eloquent::serialize(
    \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\Relation $builder
): array;

The method provide simple interface to serialize Eloquent Query Builder.

use App\Model\User;
use Laravie\SerializesQuery\Eloquent;

$query = User::has('posts')->where('age', '>', 25);

$serializedQuery = Eloquent::serialize($query);

Unserialize

Laravie\SerializesQuery\Eloquent::unserialize(array $payload): \Illuminate\Database\Eloquent\Builder;

The method provide simple interface to unserialize Eloquent Query Builder.

use Laravie\SerializesQuery\Eloquent;


$query = Eloquent::unserialize($serializedQuery);

Fluent Query Builder

Serialize

Laravie\SerializesQuery\Query::serialize(
    \Illuminate\Database\Query\Builder $builder
): array;

The method provide simple interface to serialize Fluent Query Builder.

use Illuminate\Support\Facades\DB;
use Laravie\SerializesQuery\Query;

$query = DB::table('users')->where('age', '>', 25);

$serializedQuery = Query::serialize($query);

Unserialize

Laravie\SerializesQuery\Query::unserialize(array $payload): \Illuminate\Database\Query\Builder;

The method provide simple interface to unserialize Eloquent Builder.

use Laravie\SerializesQuery\Query;


$query = Query::unserialize($serializedQuery);