JsonApiResource
class JsonApiResource extends JsonResource (View source)
Traits
Properties
| static protected array | $macros | The registered string macros. |
from Macroable |
| mixed | $resource | The resource instance. |
from JsonResource |
| array | $with | The additional data that should be added to the top-level resource array. |
from JsonResource |
| array | $additional | The additional meta data that should be added to the resource response. |
from JsonResource |
| static string|null | $wrap | The "data" wrapper that should be applied. |
|
| static bool | $forceWrapping | Whether to force wrapping even if the $wrap key exists in underlying resource data. |
from JsonResource |
| protected | $usesRequestQueryString | Determine whether resources respect inclusions and fields from the request. |
from ResolvesJsonApiElements |
| protected | $includesPreviouslyLoadedRelationships | Determine whether included relationship for the resource from eager loaded relationship. |
from ResolvesJsonApiElements |
| $loadedRelationshipsMap | Cached loaded relationships map. |
from ResolvesJsonApiElements | |
| protected | $loadedRelationshipIdentifiers | Cached loaded relationships identifers. |
from ResolvesJsonApiElements |
| static | $maxRelationshipDepth | The maximum relationship depth. |
from ResolvesJsonApiElements |
| static | $jsonApiInformation | The resource's "version" for JSON:API. |
|
| protected | $jsonApiLinks | The resource's "links" for JSON:API. |
|
| protected | $jsonApiMeta | The resource's "meta" for JSON:API. |
Methods
Filter the given data, removing any optional values.
Merge the given data in at the given index.
Remove the missing values from the filtered data.
Retrieve a value if the given "condition" is truthy.
Retrieve a value if the given "condition" is falsy.
Merge a value into the array.
Merge a value if the given condition is truthy.
Merge a value unless the given condition is truthy.
Merge the given attributes.
Retrieve an attribute if it exists on the resource.
Retrieve a model attribute if it is null.
Retrieve a model attribute if it is not null.
Retrieve an accessor when it has been appended.
Retrieve a relationship if it has been loaded.
Retrieve a relationship count if it exists.
Retrieve a relationship aggregated value if it exists.
Retrieve a relationship existence check if it exists.
Execute a callback if the given pivot table has been loaded.
Execute a callback if the given pivot table with a custom accessor has been loaded.
Determine if the resource has the specified pivot table loaded.
Determine if the resource has the specified pivot table loaded with a custom accessor.
Transform the given value if it is present.
Forward a method call to the given object.
Forward a method call to the given object, returning $this if the forwarded call returned itself.
Throw a bad method call exception for the given method.
Mix another object into the class.
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Retrieve the model for a bound value.
Retrieve the model for a bound value.
Set the value for a given offset.
Determine if an attribute exists on the resource.
Dynamically get properties from the underlying resource.
Create a new anonymous resource collection.
Create a new resource collection instance.
Convert the resource to pretty print formatted JSON.
Get the JSON serialization options that should be applied to the resource response.
Customize the outgoing response for the resource.
Resolve the HTTP request instance from container.
Set the string that should wrap the outer-most resource array.
Disable wrapping of the outer-most resource array.
Flush the resource's global state.
Specify the maximum relationship depth.
Resolve the resource's attributes.
Resolves relationships for the resource's data object.
Compile resource relations.
Compile included relationships map.
Resolve the meta information for the resource.
Indicate that relationship loading should respect the request's "includes" query string.
Indicate that relationship loading should not rely on the request's "includes" query string.
Determine relationship should include loaded relationships.
Resolve a JSON API request instance from the given HTTP request.
Set the JSON:API version for the request.
Details
protected array
filter(array $data)
Filter the given data, removing any optional values.
protected array
mergeData(array $data, int $index, array $merge, bool $numericKeys)
Merge the given data in at the given index.
protected array
removeMissingValues(array $data)
Remove the missing values from the filtered data.
protected MissingValue|mixed
when(bool $condition, mixed $value, mixed $default = new MissingValue())
Retrieve a value if the given "condition" is truthy.
MissingValue|mixed
unless(bool $condition, mixed $value, mixed $default = new MissingValue())
Retrieve a value if the given "condition" is falsy.
protected MergeValue|mixed
merge(mixed $value)
Merge a value into the array.
protected MergeValue|mixed
mergeWhen(bool $condition, mixed $value, mixed $default = new MissingValue())
Merge a value if the given condition is truthy.
protected MergeValue|mixed
mergeUnless(bool $condition, mixed $value, mixed $default = new MissingValue())
Merge a value unless the given condition is truthy.
protected MergeValue
attributes(array $attributes)
Merge the given attributes.
MissingValue|mixed
whenHas(string $attribute, mixed $value = null, mixed $default = new MissingValue())
Retrieve an attribute if it exists on the resource.
protected MissingValue|mixed
whenNull(mixed $value, mixed $default = new MissingValue())
Retrieve a model attribute if it is null.
protected MissingValue|mixed
whenNotNull(mixed $value, mixed $default = new MissingValue())
Retrieve a model attribute if it is not null.
protected MissingValue|mixed
whenAppended(string $attribute, mixed $value = null, mixed $default = new MissingValue())
Retrieve an accessor when it has been appended.
protected MissingValue|mixed
whenLoaded(string $relationship, mixed $value = null, mixed $default = new MissingValue())
Retrieve a relationship if it has been loaded.
MissingValue|mixed
whenCounted(string $relationship, mixed $value = null, mixed $default = new MissingValue())
Retrieve a relationship count if it exists.
MissingValue|mixed
whenAggregated(string $relationship, string $column, string $aggregate, mixed $value = null, mixed $default = new MissingValue())
Retrieve a relationship aggregated value if it exists.
MissingValue|mixed
whenExistsLoaded(string $relationship, mixed $value = null, mixed $default = new MissingValue())
Retrieve a relationship existence check if it exists.
protected MissingValue|mixed
whenPivotLoaded(string $table, mixed $value, mixed $default = new MissingValue())
Execute a callback if the given pivot table has been loaded.
protected MissingValue|mixed
whenPivotLoadedAs(string $accessor, string $table, mixed $value, mixed $default = new MissingValue())
Execute a callback if the given pivot table with a custom accessor has been loaded.
protected bool
hasPivotLoaded(string $table)
Determine if the resource has the specified pivot table loaded.
protected bool
hasPivotLoadedAs(string $accessor, string $table)
Determine if the resource has the specified pivot table loaded with a custom accessor.
protected mixed
transform(mixed $value, callable $callback, mixed $default = new MissingValue())
Transform the given value if it is present.
protected mixed
forwardCallTo(mixed $object, string $method, array $parameters)
Forward a method call to the given object.
protected mixed
forwardDecoratedCallTo(mixed $object, string $method, array $parameters)
Forward a method call to the given object, returning $this if the forwarded call returned itself.
static protected never
throwBadMethodCallException(string $method)
Throw a bad method call exception for the given method.
static void
macro(string $name, object|callable $macro)
Register a custom macro.
static void
mixin(object $mixin, bool $replace = true)
Mix another object into the class.
static bool
hasMacro(string $name)
Checks if macro is registered.
static void
flushMacros()
Flush the existing macros.
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
mixed
getRouteKey()
Get the value of the resource's route key.
string
getRouteKeyName()
Get the route key for the resource.
void
resolveRouteBinding(mixed $value, string|null $field = null)
Retrieve the model for a bound value.
void
resolveChildRouteBinding(string $childType, mixed $value, string|null $field = null)
Retrieve the model for a bound value.
bool
offsetExists(mixed $offset)
Determine if the given attribute exists.
mixed
offsetGet(mixed $offset)
Get the value for a given offset.
void
offsetSet(mixed $offset, mixed $value)
Set the value for a given offset.
void
offsetUnset(mixed $offset)
Unset the value for a given offset.
bool
__isset(string $key)
Determine if an attribute exists on the resource.
void
__unset(string $key)
Unset an attribute on the resource.
mixed
__get(string $key)
Dynamically get properties from the underlying resource.
__construct(mixed $resource)
Create a new resource instance.
static JsonResource
make(mixed ...$parameters)
Create a new resource instance.
static AnonymousResourceCollection
collection(mixed $resource)
Create a new anonymous resource collection.
static protected AnonymousResourceCollection
newCollection(mixed $resource)
Create a new resource collection instance.
array
resolve(Request|null $request = null)
Resolve the resource to an array.
array|Arrayable|JsonSerializable
toAttributes(Request $request)
Transform the resource into an array.
array
resolveResourceData(Request $request)
Resolve the resource data to an array.
array|Arrayable|JsonSerializable
toArray(Request $request)
Transform the resource into an array.
string
toJson(int $options = 0)
Convert the resource to JSON.
string
toPrettyJson(int $options = 0)
Convert the resource to pretty print formatted JSON.
array
with(Request $request)
Get any additional data that should be returned with the resource array.
$this
additional(array $data)
Add additional meta data to the resource response.
int
jsonOptions()
Get the JSON serialization options that should be applied to the resource response.
void
withResponse(Request $request, JsonResponse $response)
Customize the outgoing response for the resource.
protected Request
resolveRequestFromContainer()
Resolve the HTTP request instance from container.
static void
wrap(string $value)
Set the string that should wrap the outer-most resource array.
static void
withoutWrapping()
Disable wrapping of the outer-most resource array.
JsonResponse
response(Request|null $request = null)
Transform the resource into an HTTP response.
Response
toResponse(Request $request)
Create an HTTP response that represents the object.
array
jsonSerialize()
Prepare the resource for JSON serialization.
static void
flushState()
Flush the resource's global state.
static void
maxRelationshipDepth(int $depth)
Specify the maximum relationship depth.
protected array
resolveResourceObject(JsonApiRequest $request)
Resolves data for the resource.
string
resolveResourceIdentifier(JsonApiRequest $request)
Resolve the resource's identifier.
string
resolveResourceType(JsonApiRequest $request)
Resolve the resource's type.
protected array
resolveResourceAttributes(JsonApiRequest $request, string $resourceType)
Resolve the resource's attributes.
protected array
resolveResourceRelationshipIdentifiers(JsonApiRequest $request)
Resolves relationships for the resource's data object.
protected void
compileResourceRelationships(JsonApiRequest $request)
Compile resource relationships.
protected Generator
compileResourceRelationshipUsingResolver(JsonApiRequest $request, mixed $resource, RelationResolver $relationResolver, Model|null $relatedModels)
Compile resource relations.
protected void
compileIncludedNestedRelationshipsMap(JsonApiRequest $request, Model $relation, JsonApiResource $resource)
Compile included relationships map.
Collection
resolveIncludedResourceObjects(JsonApiRequest $request)
Resolves included for the resource.
protected array
resolveResourceLinks(JsonApiRequest $request)
Resolve the links for the resource.
protected array
resolveResourceMetaInformation(JsonApiRequest $request)
Resolve the meta information for the resource.
$this
respectFieldsAndIncludesInQueryString(bool $value = true)
Indicate that relationship loading should respect the request's "includes" query string.
$this
ignoreFieldsAndIncludesInQueryString()
Indicate that relationship loading should not rely on the request's "includes" query string.
$this
includePreviouslyLoadedRelationships()
Determine relationship should include loaded relationships.
protected JsonApiRequest
resolveJsonApiRequestFrom(Request $request)
Resolve a JSON API request instance from the given HTTP request.
static void
configure(string|null $version = null, array $ext = [], array $profile = [], array $meta = [])
Set the JSON:API version for the request.
string|null
toId(Request $request)
Get the resource's ID.
string|null
toType(Request $request)
Get the resource's type.
array
toLinks(Request $request)
Get the resource's links.
array
toMeta(Request $request)
Get the resource's meta information.