Package to allow Symfony Serializer to work on Eloquent models.
You can use Composer to install the bundle to your project:
composer require theofidry/eloquent-serializer
Nothing to do, the provider is automatically discovered :)
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;
}
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',
// ];
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