Answer the question
In order to leave comments, you need to log in
How to return an object with relations as objects?
I give out a list of objects via api in the form of json.
An object has relationships with other classes through belongTo and so on.
By default, when using this method,
I get the id of related objects in json.
Of course, before returning, I can bypass the array of returned objects and push each entity instead of id, but these are some kind of crutches.
Maybe there is a regular way that I can't find in the docks? return response()->json($events, 200);
Answer the question
In order to leave comments, you need to log in
Is there a regular way that I can't find in the docks?https://laravel.com/docs/6.0/eloquent-resources
If possible, it is best to add to the with request.
If not, then you can call entities by relationships, then the data will appear in the $events object
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question