theofidry/eloquent-serializer

This package is abandoned and no longer maintained. No replacement package was suggested.

Symfony Serializer bridge for the Eloquent ORM.

Installs: 3 568

Dependents: 0

Suggesters: 0

Security: 0

Stars: 11

Watchers: 2

Forks: 4

Open Issues: 0

Type:laravel-provider

v1.1.0 2017-12-17 23:54 UTC

This package is auto-updated.

Last update: 2020-04-18 16:38:42 UTC


README

Package version Build Status License

Package to allow Symfony Serializer to work on Eloquent models.

Table of Contents

  1. Install
    1. Laravel
    2. Symfony
  2. Usage
  3. Contributing

Install

You can use Composer to install the bundle to your project:

composer require theofidry/eloquent-serializer

Laravel (~5.5.0)

Nothing to do, the provider is automatically discovered :)

Symfony (^3.4 || ^4.0)

Enable the bundle by updating your app/AppKernel.php file to enable the bundle:

<?php
// app/AppKernel.php

public function registerBundles()
{
    //...
    $bundles[] = new \Fidry\EloquentSerializer\Bridge\Symfony\FidryEloquentSerializerBundle();

    return $bundles;
}

Usage

use Fidry\EloquentSerializer\Bridge\Laravel\Facade\Serializer;

// Dummy is an Eloquent model
$dummy = Dummy::create([
    'id' => 100,
    'name' => 'Gunner Runte',
    'email' => 'vbrekke@example.com',
    'password' => '$2y$10$j/R4kRrymk3wMXwohvoRou2zBKJZVecr1VON.9NnSXu24k6CP6tDe',
    'remember_token' => 'PhiasHkmCh',
    'created_at' => new Carbon('2016-07-02T12:28:14+00:00'),
]);

// You can either use the Facade (Laravel) or the 'serializer' service (Laravel & Symfony)
$normalizedDummy = Serializer::normalize($dummy);

// $normalizedDummy: [
//     'id' => 100,
//     'name' => 'Gunner Runte',
//     'email' => 'vbrekke@example.com',
//     'created_at' => '2016-07-02T12:28:14+00:00',
// ];

Contributing

You can find two bash scripts to help with the testing:

bin/setup   # Install the dependencies and setup the sqlite database
bin/tests   # Runs the tests