Comments (8)
The 'items.results' = null
is actually a bug and something I'm addressing for the next release. You should, however, see results nested under items as well. Could you paste the results
method in your ItemTransformer?
from laravel-responder.
Of course,
public function results(Item $item)
{
return $this -> collection($item -> results, new ResultTransformer);
}
Nothing special with this method, I guess...
What is remarkable is that the key 'items.results' = null
only appears one time, at the end of the last item...
Thanks.
from laravel-responder.
Hmm, I'm working on a rewrite of the package improving the including of relations, which should solve these issues. I'll try to recreate the issue described above, but could you try to change the results
method to the following:
public function results(Item $item) {
return responder()->transform($item->results, new ResultTransformer)->getResource();
}
from laravel-responder.
Of course.
I have modified the method with your suggestion and I get the same 'items.results' = null
key at the end...
(Assuming that in the controller I have:
...new SurveyTransformer) ->include(['items.results']) -> respond();
)
I really appreciate your help.
from laravel-responder.
Hey, sorry for taking so long. After some investigating, I've located the bug. The issue is when using the wildcard relations on deeply nested transformers, like:
protected $relations = ['*'];
For some reason, that doesn't work as intended for nested relations. However, it can be fixed by explicitly specifying the relationship, which in your case would be to add $relations = ['results']
to ItemTransformer
.
I tested the same with the upcoming version 2 of the package, and everything worked as expected. So this should be solved by that in a couple weeks time - in the mean time, you will have to be explicit with the relations (which often can be a good idea anyway, as it can restrict access to some relations for security reasons).
Let me know if that solved all your issues!
from laravel-responder.
Thank you very much for your help, but that change does not fix the issue in my specific case...
I have done the changes to ItemTransformer
so that protected $relations = ['results']
, and it keeps returning the 'items.results' = null
at the end.
I have also tried with both
return responder()->transform($item->results, new ResultTransformer)->getResource();
and
return $this -> collection($item -> results, new ResultTransformer);
in the results
method, no luck...
However, noticed that when I change protected $relations = ['items']
in SurveyTransformer
, results
does not appear, but neither 'items.results' = null
key.
Thanks again.
from laravel-responder.
Oh, I thought the issue was that you didn't get the 'results'
data at all. Is this still the case? The 'items.results': null
at the end is a bug I tried to fix earlier this winter. However, while trying to fix it, I realised the entire code for handling relations was way too complex, and instead of fixing it, I ended up rewriting big parts of the package (for the better). These changes will be rolled out soon and will fix the 'items.results': null
bug. In the meantime, the bug shouldn't actually break anything, only add an unnecessary JSON field to the response.
from laravel-responder.
With the release of version 2 of the package, this bug should have vanished.
from laravel-responder.
Related Issues (20)
- Transformer mappings circular dependencies
- php 8 support HOT 1
- ConvertToSnakeCase throwing an "Undefined function" error
- error HOT 1
- Transforming To Camel Case in Lumen
- How do I use getResourceKey() on Relationship?
- Transformer not applied HOT 1
- Include message in success response HOT 1
- Laravel Responder installation in Laravel 9 is not working. HOT 11
- Fractal 0.20.0 supprot HOT 3
- I wish there was an *except* method
- Laravel 10 support HOT 7
- composer require flugger/laravel-responder error laravel 10 HOT 4
- Laravel 10 support!
- Different types in NoopSerializer HOT 9
- Wrong Model Namespace on executing the transformer command
- Support for simplePaginate
- Language files folder
- Flugg\Responder\Serializers\NoopSerializer error for method null HOT 3
- Laravel 11 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-responder.