abstract class Resource implements AppendableData, BaseData, Castable, EmptyData, IncludeableData, ResponsableData, TransformableData, WrappableData

Traits

Properties

protected array $_additional from  AppendableData
protected PartialsDefinition|false|null $partialDefinitions

Null before defaults are inspected, false when they are empty, or the mutable definition store.

from  IncludeableData
protected Wrap|null $wrap from  WrappableData

Methods

array
with()

Get the additional data defined by the data object.

additional(array $additional)

Add top-level data to the response.

array
getAdditionalData()

Get the resolved additional response data.

castRequestUsing(array $arguments)

Get the request caster for the data object.

static BaseData|null
optional(mixed ...$payloads)

Create an optional data object.

from  BaseData
static BaseData
from(mixed ...$payloads)

Create a data object.

from  BaseData
factory()

Create a fresh data construction factory.

from  BaseData
static array
normalizers()

Get the class-owned data normalizers.

from  BaseData
static BaseData
newInstance(Request $request)

Create a data object from the current request.

from  BaseData
castUsing(array $arguments)

Get the Eloquent caster for the data object.

static array
empty(array $extra = [], mixed $replaceNullValuesWith = null, array|null $except = null, array|null $only = null)

Create an empty representation of the data class.

getPartialsDefinition()

Get the partial definition store.

include(string ...$includes)

Include properties for the next transformation.

includePermanently(string ...$includes)

Include properties for every transformation.

exclude(string ...$excludes)

Exclude lazy properties for the next transformation.

excludePermanently(string ...$excludes)

Exclude lazy properties for every transformation.

only(string ...$only)

Keep only properties for the next transformation.

onlyPermanently(string ...$only)

Keep only properties for every transformation.

except(string ...$except)

Exclude properties for the next transformation.

exceptPermanently(string ...$except)

Exclude properties for every transformation.

includeWhen(string $include, bool|Closure $condition, bool $permanent = false)

Include a property when the condition passes.

excludeWhen(string $exclude, bool|Closure $condition, bool $permanent = false)

Exclude a lazy property when the condition passes.

onlyWhen(string $only, bool|Closure $condition, bool $permanent = false)

Keep only a property when the condition passes.

exceptWhen(string $except, bool|Closure $condition, bool $permanent = false)

Exclude a property when the condition passes.

bool
hasPartialsDefinition()

Determine whether this object has partial definitions.

array
includeProperties()

Get class-owned permanent include definitions.

array
excludeProperties()

Get class-owned permanent exclude definitions.

array
onlyProperties()

Get class-owned permanent only definitions.

array
exceptProperties()

Get class-owned permanent except definitions.

toResponse(Request $request)

Create an HTTP response that represents the data object.

static int
jsonOptions()

Get the JSON serialization options for the resource response.

void
withResponse(Request $request, JsonResponse $response)

Customize the outgoing resource response.

static array|null
allowedRequestIncludes()

Get the request properties that may be included.

static array|null
allowedRequestExcludes()

Get the request properties that may be excluded.

static array|null
allowedRequestOnly()

Get the request properties allowed by an only selection.

static array|null
allowedRequestExcept()

Get the request properties allowed by an except selection.

responseItems(BaseDataCollectable $data)

Get original collection items without transforming or enumerating them twice.

array
transform(TransformationContextFactory|TransformationContext|null $transformationContext = null)

Transform the data object to an array.

array
all()

Get all visible properties without transforming their values.

array
toArray()

Get the data object as an array.

string
toJson(int $options = 0)

Convert the data object to its JSON representation.

array
jsonSerialize()

Get the data that should be serialized to JSON.

withoutWrapping()

Disable wrapping for the data object.

wrap(string $key)

Wrap the data object with the given key.

getWrap()

Get the current wrapping definition.

Details

in AppendableData at line 16
array with()

Get the additional data defined by the data object.

Return Value

array

in AppendableData at line 24
AppendableData additional(array $additional)

Add top-level data to the response.

Parameters

array $additional

Return Value

AppendableData

in AppendableData at line 34
array getAdditionalData()

Get the resolved additional response data.

Return Value

array

static CastsRequestInput castRequestUsing(array $arguments)

Get the request caster for the data object.

Parameters

array $arguments

Return Value

CastsRequestInput

in BaseData at line 37
static BaseData|null optional(mixed ...$payloads)

Create an optional data object.

Parameters

mixed ...$payloads

Return Value

BaseData|null

in BaseData at line 55
static BaseData from(mixed ...$payloads)

Create a data object.

Parameters

mixed ...$payloads

Return Value

BaseData

in BaseData at line 132
static array|DataCollection|PaginatedDataCollection|CursorPaginatedDataCollection|Enumerable|AbstractPaginator|Paginator|AbstractCursorPaginator|CursorPaginator|LazyCollection|Collection collect(mixed $items, string|null $into = null)

Collect data objects.

Contract-typed sources retain every possible rebuildable runtime shape.

in BaseData at line 145
static CreationContextFactory factory()

Create a fresh data construction factory.

Return Value

CreationContextFactory

in BaseData at line 158
static array normalizers()

Get the class-owned data normalizers.

Return Value

array

in BaseData at line 168
static BaseData newInstance(Request $request)

Create a data object from the current request.

Parameters

Request $request

Return Value

BaseData

static CastsAttributes|CastsInboundAttributes|string castUsing(array $arguments)

Get the Eloquent caster for the data object.

Parameters

array $arguments

Return Value

CastsAttributes|CastsInboundAttributes|string

in EmptyData at line 16
static array empty(array $extra = [], mixed $replaceNullValuesWith = null, array|null $except = null, array|null $only = null)

Create an empty representation of the data class.

Parameters

array $extra
mixed $replaceNullValuesWith
array|null $except
array|null $only

Return Value

array

abstract protected PartialsDefinition getPartialsDefinition()

Get the partial definition store.

Return Value

PartialsDefinition

ForwardsToPartialsDefinition include(string ...$includes)

Include properties for the next transformation.

Parameters

string ...$includes

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition includePermanently(string ...$includes)

Include properties for every transformation.

Parameters

string ...$includes

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition exclude(string ...$excludes)

Exclude lazy properties for the next transformation.

Parameters

string ...$excludes

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition excludePermanently(string ...$excludes)

Exclude lazy properties for every transformation.

Parameters

string ...$excludes

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition only(string ...$only)

Keep only properties for the next transformation.

Parameters

string ...$only

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition onlyPermanently(string ...$only)

Keep only properties for every transformation.

Parameters

string ...$only

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition except(string ...$except)

Exclude properties for the next transformation.

Parameters

string ...$except

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition exceptPermanently(string ...$except)

Exclude properties for every transformation.

Parameters

string ...$except

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition includeWhen(string $include, bool|Closure $condition, bool $permanent = false)

Include a property when the condition passes.

Parameters

string $include
bool|Closure $condition
bool $permanent

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition excludeWhen(string $exclude, bool|Closure $condition, bool $permanent = false)

Exclude a lazy property when the condition passes.

Parameters

string $exclude
bool|Closure $condition
bool $permanent

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition onlyWhen(string $only, bool|Closure $condition, bool $permanent = false)

Keep only a property when the condition passes.

Parameters

string $only
bool|Closure $condition
bool $permanent

Return Value

ForwardsToPartialsDefinition

ForwardsToPartialsDefinition exceptWhen(string $except, bool|Closure $condition, bool $permanent = false)

Exclude a property when the condition passes.

Parameters

string $except
bool|Closure $condition
bool $permanent

Return Value

ForwardsToPartialsDefinition

in IncludeableData at line 24
bool hasPartialsDefinition()

Determine whether this object has partial definitions.

Return Value

bool

in IncludeableData at line 88
protected array includeProperties()

Get class-owned permanent include definitions.

Return Value

array

in IncludeableData at line 96
protected array excludeProperties()

Get class-owned permanent exclude definitions.

Return Value

array

in IncludeableData at line 104
protected array onlyProperties()

Get class-owned permanent only definitions.

Return Value

array

in IncludeableData at line 112
protected array exceptProperties()

Get class-owned permanent except definitions.

Return Value

array

in ResponsableData at line 28
JsonResponse toResponse(Request $request)

Create an HTTP response that represents the data object.

Parameters

Request $request

Return Value

JsonResponse

in ResponsableData at line 67
static int jsonOptions()

Get the JSON serialization options for the resource response.

Return Value

int

in ResponsableData at line 75
void withResponse(Request $request, JsonResponse $response)

Customize the outgoing resource response.

Parameters

Request $request
JsonResponse $response

Return Value

void

in ResponsableData at line 82
static array|null allowedRequestIncludes()

Get the request properties that may be included.

Return Value

array|null

in ResponsableData at line 90
static array|null allowedRequestExcludes()

Get the request properties that may be excluded.

Return Value

array|null

in ResponsableData at line 98
static array|null allowedRequestOnly()

Get the request properties allowed by an only selection.

Return Value

array|null

in ResponsableData at line 106
static array|null allowedRequestExcept()

Get the request properties allowed by an except selection.

Return Value

array|null

in ResponsableData at line 116
protected Collection responseItems(BaseDataCollectable $data)

Get original collection items without transforming or enumerating them twice.

Parameters

BaseDataCollectable $data

Return Value

Collection

in TransformableData at line 20
array transform(TransformationContextFactory|TransformationContext|null $transformationContext = null)

Transform the data object to an array.

Parameters

TransformationContextFactory|TransformationContext|null $transformationContext

Return Value

array

in TransformableData at line 38
array all()

Get all visible properties without transforming their values.

Return Value

array

in TransformableData at line 52
array toArray()

Get the data object as an array.

Return Value

array

in TransformableData at line 60
string toJson(int $options = 0)

Convert the data object to its JSON representation.

Parameters

int $options

Return Value

string

in TransformableData at line 70
array jsonSerialize()

Get the data that should be serialized to JSON.

Return Value

array

in WrappableData at line 17
WrappableData withoutWrapping()

Disable wrapping for the data object.

Return Value

WrappableData

in WrappableData at line 27
WrappableData wrap(string $key)

Wrap the data object with the given key.

Parameters

string $key

Return Value

WrappableData

in WrappableData at line 37
Wrap getWrap()

Get the current wrapping definition.

Return Value

Wrap