8000 Update docs with snake_case attributes explanation by martynling · Pull Request #1 · martynling/laravel-json-api · GitHub
[go: up one dir, main page]

Skip to content

Update docs with snake_case attributes explanation #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,35 @@ encode Eloquent models to JSON API resources, others will use a mixture of Eloqu
or might not even be using Eloquent models.

So we decided to refer to PHP object instances that are converted to JSON API resources as *records*.

### Handling snake_case attributes

**snake_case** eloquent model attributes are handled automatically by laravel-json-api via the `$attributes` property on the Hydrator and Schema resource units. The Schema needs the snake_case representation of the attribute and the Hydrator needs the kebab-case representation of the attribute. For example:

Posts\Schema.php
```
class Schema extends EloquentSchema
{
/**
* @var array|null
*/
protected $attributes = [
'phone_number',
// ... other attributes
];
...
```

Posts\Hydrator.php
```
class Hydrator extends EloquentHydrator
{
/**
* @var array|null
*/
protected $attributes = [
'phone-number',
// ... other attributes
];
...
```
0