Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reyesoft/jsonapi-playground
Laravel JSON:API 1.0 served with Eloquent Models data, schemas and policies.
https://github.com/reyesoft/jsonapi-playground
jsonapi laravel playground
Last synced: 7 days ago
JSON representation
Laravel JSON:API 1.0 served with Eloquent Models data, schemas and policies.
- Host: GitHub
- URL: https://github.com/reyesoft/jsonapi-playground
- Owner: reyesoft
- Created: 2019-09-02T22:15:17.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-09-21T19:37:30.000Z (over 5 years ago)
- Last Synced: 2024-11-09T12:36:12.320Z (2 months ago)
- Topics: jsonapi, laravel, playground
- Language: PHP
- Homepage: http://jsonapiplayground.reyesoft.com/
- Size: 714 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JsonApi Playground
Free data service for JSON:API clients testing: 😁
## Notice
This example uses a private library (`laravel-json-api`) and purchase is required if you need generate your own data server.
## Resources
- authors
- books
- series
- chapters
- stores
- photos## Development
### Defining a schema for Model
```php
class AuthorSchema extends SchemaProvider
{
protected $resourceType = 'authors';
public static $policy = AuthorPolicy::class;
public static $model = Author::class;
protected static $attributes = [];
protected static $relationships = [];public static function boot(): void {
self::addAttribute('name')
->setFilter(StringFilter::class)
->sortable();
self::addAttribute('birthplace')
->setCru('r');
self::addAttribute('date_of_birth');
self::addAttribute('date_of_death');self::addRelationship(PhotoSchema::class, 'photos')
->setHasMany();
self::addRelationship(BookSchema::class, 'books')
->setHasMany();
}
}
```#### Explanation
`$policy` define policies for your calls. For example block by user permissions or if user is the owner of resource.
`setFilter(StringFilter::class)` add the possibility to do calls like (more options available)
```
GET /authors?filter[name]=Ray
GET /authors?filter[name][eq]=Ray
GET /authors?filter[name][contains]=Ray
````sortable()` add the possibility to do calls like
```
GET /authors?sort=name
GET /authors?sort=-name
````setCru('r')` you can only read value, you cannot set con Create (c) or Update (u). Default value for CRU parameter is `cru`.