Skip to content

Commit

Permalink
Update README (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
f3ath authored Oct 25, 2017
1 parent 266d153 commit 7615a38
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@ A simple example to illustrate the general idea. This JSON representation from
}
}
```
can be built with the following php code (less imports):
can be built with the following php code:
<!-- assert=output expect=my_json -->
```php
<?php
$articles = new \JsonApiPhp\JsonApi\Document\Resource\ResourceObject('articles', '1');
$author = \JsonApiPhp\JsonApi\Document\Resource\Relationship::fromLinkage(
new \JsonApiPhp\JsonApi\Document\Resource\Linkage\SingleLinkage(
new \JsonApiPhp\JsonApi\Document\Resource\ResourceIdentifier('people', '9')
)
);
use \JsonApiPhp\JsonApi\Document;
use \JsonApiPhp\JsonApi\Document\Resource\{
Linkage\SingleLinkage, Relationship, ResourceIdentifier, ResourceObject
};

$author = Relationship::fromLinkage(new SingleLinkage(new ResourceIdentifier('people', '9')));
$author->setLink('self', '/articles/1/relationships/author');
$author->setLink('related','/articles/1/author');
$author->setLink('related', '/articles/1/author');
$articles = new ResourceObject('articles', '1');
$articles->setRelationship('author', $author);
$articles->setAttribute('title', 'Rails is Omakase');
$doc = \JsonApiPhp\JsonApi\Document::fromResource($articles);
echo json_encode($doc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
echo json_encode(Document::fromResource($articles), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
```

Please refer to [the tests](./test) for the full API documentation:
Expand Down

0 comments on commit 7615a38

Please sign in to comment.