Support the ongoing development of Laravel.io →
posted 11 years ago
Requests

Hi there, I am using Ember.js (http://emberjs.com/) for developing most of my frontend-applications and now using it in combination with Laravel as the backend, providing the REST-API.

There is one 'problem' though, when I want to provide a resource that includes a many-to-many relationship. So the code would be something like, Model::with(array('relationship1', 'relationship2')->get()->toArray(); and so far I am providing the resource via Response::json(compact('model')), which works when I provide simple models, but ember.js expects relationships to be sideloaded in a different way as provided here:

http://emberjs.com/guides/models/connecting-to-an-http-server/#toc_json-conventions

Is there any simple way of making Laravel provide my resources with relationships in that format? Right now I am creating the JSON response manually, which is quite tedious. Would be extremely helpful if anyone knows a better way. Thanks for any help.

Last updated 3 years ago.
0

Check out the package rtablada/eloquent-ember

That should do what you want.

Last updated 3 years ago.
0

Thank you my dear sir. That could have saved me hours of work yesterday.

Last updated 3 years ago.
0

I gave up on ember. To frustrating, but the package is awesome!

Last updated 3 years ago.
0

Sign in to participate in this thread!

PHPverse

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.