nilportugues / laravel5-jsonapi

Laravel 5 JSON API Transformer Package

Home Page:http://nilportugues.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to add default values to POST, query by a scope

marceloandrader opened this issue · comments

Hey, thanks for this library I'm just starting to use it and looks really promising.

One thing that my app has is that is multi-tenant, so most of the api endpoints will return data with a specific scope, in a normal index controller I can do Entity::forOrg(Auth::user()->organization_id) returning only the Entity for the org of the user. What is the best way to do that on the JsonApiController subclasses?

And also when creating this kind of records, I need to set that organization_id column to the value of the user->organization_id, thanks in advance.

I was able to fix the scope issue using global scopes.

But the other thing I tried setting the organization_id on the Entity::creating event, but that is never fired, looks like the DataObject expects all fields on the attributes key and get an error about 2 fields, one is the org_id that is not sent and the other is a relationship field.

I'm using Ember data to try to make a POST, so the POST looks like:

post

And the response is:

response