# Attributes
Define an attribute field (opens new window) on your resource using the attribute method.
$type->attribute('firstName');
By default, the attribute will read and write to the property on your model with the same name. (The Eloquent adapter will snake_case it automatically for you.) If you'd like it to correspond to a different property, use the property method:
$type->attribute('firstName')
->property('fname');
# Getters
Use the get method to define custom retrieval logic for your attribute, instead of just reading the value straight from the model property.
use Tobyz\JsonApiServer\Context;
$type->attribute('firstName')
->get(function ($model, Context $context) {
return ucfirst($model->first_name);
});
TIP
If you're using Eloquent, you could also define attribute casts (opens new window) or accessors (opens new window) on your model to achieve a similar thing. However, the Request instance will not be available in this context.
← Scopes Relationships →