Laravel 5 Customize Serialize Data

Hello Everyone,

First question on this forum…

I’m pretty new in ember,

I want to load users, but in my JSON response is:

{ "total":3, "per_page":20, "current_page":1, "last_page":1, "next_page_url":null, "prev_page_url":null, "from":1, "to":3, "data":[ { "id":7, "email":"rizki@talenta.co", "first_name":"Rizki", "last_name":"Andrianto", "created_at":"2016-06-28 08:54:28", "updated_at":"2016-06-28 08:54:28" }, { "id":21, "email":"yansen@talenta.co", "first_name":"Yansen", "last_name":"Tan", "created_at":"2016-07-21 10:12:21", "updated_at":"2016-07-21 10:12:21" }, { "id":115, "email":"uray@talenta.co", "first_name":"Uray", "last_name":"Chrisna", "created_at":"2016-07-29 14 :13:35", "updated_at":"2016-07-29 14:13:35" } ] }

and my app/model/users:

//import Model from 'ember-data/model';
import DS from 'ember-data';

export default DS.Model.extend({
	total: DS.attr('number'),
	per_page: DS.attr('number'),
	current_page: DS.attr('number'),
	last_page: DS.attr('number'),
	next_page_url: DS.attr('string'),
	users: DS.attr()
});

but I get : WARNING: Encountered "data" in payload, but no model was found for model name "datum" (resolved model name using ember-jwt@serializer:-rest:.modelNameFromPayloadKey("data"))

How to display only the user or all of them without changin the backend? I want to google this, but I don’t know the keyword…

Thank you…

What you’ll need is a custom serializer to change your backend data into a format that Ember Data expects. I’d start here (Customizing Serializers - Models - Ember Guides) but also search for tutorials on the subject, there have been some good ones in the last 6 months.

Thanks for the reply,

Oh I see, custom serializer. But that’s article is for POST not for GET, right? is it the same way?

You can also send JSON-API formatted data from your server, might be a better idea if you have control over server responses. Check out https://github.com/cloudcreativity/json-api , which is based on https://github.com/neomerx?tab=repositories , you can also check limoncello-* packages and sample ember apps.

Confirmed, it works the same way

This is also a good point. @rizkiandrianto, depending on whether you are able to change your API somewhat drastically, using JSON-API will make your life simpler in the long-run with Ember Data. There are some growing pains to the JSON-API spec (things that need to get worked through still), but it’s growing closer and closer to “drop-in ready” for the types of advanced use cases needed on the Ember side of things …

I’ve followed the instruction from ember.js - Incorrect JSON format for Ember Data - Stack Overflow

but it still gets those warning, and doesn’t show anything on template.