theofidry / eloquent-serializer
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
Requires
- php: ^7.1
- illuminate/database: ~5.5.0
- symfony/property-access: ^3.4 || ^4.0
- symfony/property-info: ^3.4 || ^4.0
- symfony/serializer: ^3.4 || ^4.0
Requires (Dev)
- bamarni/composer-bin-plugin: ^1.0
- phpunit/phpunit: ^6.4
This package is auto-updated.
Last update: 2020-04-18 16:38:42 UTC
README
Package to allow Symfony Serializer to work on Eloquent models.
Table of Contents
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