项目作者: theofidry

项目描述 :
Symfony Serializer bridge for the Eloquent ORM.
高级语言: PHP
项目地址: git://github.com/theofidry/EloquentSerializer.git
创建时间: 2016-07-02T16:26:37Z
项目社区:https://github.com/theofidry/EloquentSerializer

开源协议:MIT License

下载


EloquentSerializer

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:

  1. 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:

  1. <?php
  2. // app/AppKernel.php
  3. public function registerBundles()
  4. {
  5. //...
  6. $bundles[] = new \Fidry\EloquentSerializer\Bridge\Symfony\FidryEloquentSerializerBundle();
  7. return $bundles;
  8. }

Usage

  1. use Fidry\EloquentSerializer\Bridge\Laravel\Facade\Serializer;
  2. // Dummy is an Eloquent model
  3. $dummy = Dummy::create([
  4. 'id' => 100,
  5. 'name' => 'Gunner Runte',
  6. 'email' => 'vbrekke@example.com',
  7. 'password' => '$2y$10$j/R4kRrymk3wMXwohvoRou2zBKJZVecr1VON.9NnSXu24k6CP6tDe',
  8. 'remember_token' => 'PhiasHkmCh',
  9. 'created_at' => new Carbon('2016-07-02T12:28:14+00:00'),
  10. ]);
  11. // You can either use the Facade (Laravel) or the 'serializer' service (Laravel & Symfony)
  12. $normalizedDummy = Serializer::normalize($dummy);
  13. // $normalizedDummy: [
  14. // 'id' => 100,
  15. // 'name' => 'Gunner Runte',
  16. // 'email' => 'vbrekke@example.com',
  17. // 'created_at' => '2016-07-02T12:28:14+00:00',
  18. // ];

Contributing

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

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