Comments (2)
Hi!
I'm assuming you're on the latest version of the library (if not, just say). To get the array from the data
key, you can do:
use CloudCreativity\JsonApi\Decoders\DocumentDecoder;
use CloudCreativity\JsonApi\Object\Resource;
/** @var string $content the response content */
$decoder = new DocumentDecoder();
$document = $decoder->decode($content);
/** @var stdClass[] $data */
$data = $document->get('data');
/** If you want these as actual resource objects... */
$resources = array_map(function (stdClass $object) {
return new Resource($object);
}, $data);
The reason there isn't an inbuilt way of doing this is because the library has been built to validate content coming from a client, rather than a client handling the response from a server. However, this is definitely an intended use case for the package, we just haven't put a huge amount of dev time into it yet.
It'd be a great addition if I added support for this in, because what you're trying to do is an obvious omission for the use case of handling responses
All I need to do is add a collection that holds instances of this class:
https://github.com/cloudcreativity/json-api/blob/master/src/Contracts/Object/ResourceInterface.php
And then add a method to this interface:
https://github.com/cloudcreativity/json-api/blob/master/src/Contracts/Object/DocumentInterface.php
To get the collection from the data
key.
I'm happy to do this but I won't be able to get to it until the weekend at the earliest, or next week.
from json-api.
Closing as this change is available on the 0.6.x-dev
version and will be release at v0.6
from json-api.
Related Issues (20)
- Authorising updates needs access to what the client sent HOT 1
- Default resource document and relationship document validators HOT 2
- Inject error repository into `AbstractAuthorizer` by default HOT 1
- Make `AbstractHydrator::methodForRelationship` non-abstract HOT 1
- Store should be backed by an Identity Map HOT 1
- Invalid resource type in relationship HOT 1
- RelatedHydratorTrait needs a hydrateRelated method HOT 1
- Allow packages to add configuration to API definitions HOT 1
- Standard object iterator HOT 1
- Search All and Search Related HOT 1
- Badges HOT 3
- Validation of resource identifier with empty id HOT 4
- Add relationship methods to HTTP client
- Detect message body in responses HOT 1
- Type error after client tries request to invalid URL
- Pagination on relationships HOT 1
- How to add custom action to resource constroller? HOT 1
- the place where I can save the result of any query HOT 2
- Deprecated Error class "CloudCreativity\LaravelJsonApi\Document\Error"
- Validation Exception HOT 3
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 json-api.