nuwave / ember-eloquent by chrissm79

Laravel package to translate api responses into ember-data readable formats.
60
3
2
Package Data
Maintainer Username: chrissm79
Maintainer Contact: chris@nuwavecommerce.com (Christopher Moore)
Package Create Date: 2015-04-02
Package Last Update: 2015-07-22
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:12:59
Package Statistics
Total Downloads: 60
Monthly Downloads: 2
Daily Downloads: 1
Total Stars: 3
Total Watchers: 2
Total Forks: 2
Total Open Issues: 0

Ember-Eloquent

Introduction

I have been working quite a bit with Ember recently and I wanted to create Ember Data formatted responses including sideloading. This proeject utilizes Fractal's JsonApiSerializer and tweaks it a bit to create json responses that are consumable by ember-data.

This is still a work in progress, so please use with caution

Installation

Install the composer package

composer require nuwave/ember-eloquent

Add the service provider to you app.php file

'NuWave\Serializers\SerializerServiceProvider',

Publish the config file

php artisan vendor:publish

Create your model transformers (Fractal)

Fractal Transformer Guide

Edit the config file with your application namespace (optional: you can also add a suffix if your naming convension utilizes it)

// config/ember.php

return [
    /*
    |---------------------------------------------------------------------
    | Transformer Namespace
    |---------------------------------------------------------------------
    |
    | Set the default namespace for your transformer
    |
    */
    'namespace' => 'MyApp\Transformers',

    /*
    |---------------------------------------------------------------------
    | Transformer Suffix
    |---------------------------------------------------------------------
    |
    | Set the suffix for your transformer naming convention.
    |
    | Default value is null
    */
    'suffix' => null
];

Add EmberTrait to your controllers (or your base Controller). This will allow you to utilize the emberResponse method which takes your Model/Collection along with the model name and transforms it into an ember-data formatted response.

class UserController extends Controller {

  use EmberTrait;

  public function index()
  {
    $users = User::all();
    
    // or
    
    $users = User::paginate(20); // meta data will be included in response
    
    return $this->emberResponse($users, 'User');
  }
  
  // ...
  
  public function show($id)
  {
    $user = User::find($id);
    
    return $this->emberResponse($user, 'User');
  }
}