AnonymousResourceCollection

class AnonymousResourceCollection extends ResourceCollection (View source)

Traits

CollectsResources
ConditionallyLoadsAttributes
DelegatesToResource
ForwardsCalls

Properties

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 $wrap The "data" wrapper that should be applied. from JsonResource
string $collects The name of the resource being collected.
Collection $collection The mapped collection instance. from ResourceCollection
protected bool $preserveAllQueryParameters Indicates if all existing request query parameters should be added to pagination links. from ResourceCollection
protected array|null $queryParameters The query parameters that should be added to the pagination links. from ResourceCollection

Methods

array filter(array $data)

Filter the given data, removing any optional values.

from ConditionallyLoadsAttributes
array mergeData(array $data, int $index, array $merge, bool $numericKeys)

Merge the given data in at the given index.

from ConditionallyLoadsAttributes
array removeMissingValues(array $data)

Remove the missing values from the filtered data.

from ConditionallyLoadsAttributes
MissingValue|mixed when(bool $condition, mixed $value, mixed $default = null)

Retrieve a value based on a given condition.

from ConditionallyLoadsAttributes
MergeValue|mixed merge(mixed $value)

Merge a value into the array.

from ConditionallyLoadsAttributes
MergeValue|mixed mergeWhen(bool $condition, mixed $value)

Merge a value based on a given condition.

from ConditionallyLoadsAttributes
MergeValue attributes(array $attributes)

Merge the given attributes.

from ConditionallyLoadsAttributes
MissingValue|mixed whenLoaded(string $relationship, mixed $value = null, mixed $default = null)

Retrieve a relationship if it has been loaded.

from ConditionallyLoadsAttributes
MissingValue|mixed whenPivotLoaded(string $table, mixed $value, mixed $default = null)

Execute a callback if the given pivot table has been loaded.

from ConditionallyLoadsAttributes
MissingValue|mixed whenPivotLoadedAs(string $accessor, string $table, mixed $value, mixed $default = null)

Execute a callback if the given pivot table with a custom accessor has been loaded.

from ConditionallyLoadsAttributes
mixed transform(mixed $value, callable $callback, mixed $default = null)

Transform the given value if it is present.

from ConditionallyLoadsAttributes
mixed forwardCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object.

from ForwardsCalls
static void throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

from ForwardsCalls
mixed getRouteKey()

Get the value of the resource's route key.

from DelegatesToResource
string getRouteKeyName()

Get the route key for the resource.

from DelegatesToResource
void resolveRouteBinding(mixed $value)

Retrieve the model for a bound value.

from DelegatesToResource
bool offsetExists(mixed $offset)

Determine if the given attribute exists.

from DelegatesToResource
mixed offsetGet(mixed $offset)

Get the value for a given offset.

from DelegatesToResource
void offsetSet(mixed $offset, mixed $value)

Set the value for a given offset.

from DelegatesToResource
void offsetUnset(mixed $offset)

Unset the value for a given offset.

from DelegatesToResource
bool __isset(string $key)

Determine if an attribute exists on the resource.

from DelegatesToResource
void __unset(string $key)

Unset an attribute on the resource.

from DelegatesToResource
mixed __get(string $key)

Dynamically get properties from the underlying resource.

from DelegatesToResource
mixed __call(string $method, array $parameters)

Dynamically pass method calls to the underlying resource.

from DelegatesToResource
void __construct(mixed $resource, string $collects)

Create a new anonymous resource collection.

static JsonResource make(mixed ...$parameters)

Create a new resource instance.

from JsonResource
static AnonymousResourceCollection collection(mixed $resource)

Create new anonymous resource collection.

from JsonResource
array resolve(Request|null $request = null)

Resolve the resource to an array.

from JsonResource
array toArray(Request $request)

Transform the resource into a JSON array.

from ResourceCollection
array with(Request $request)

Get any additional data that should be returned with the resource array.

from JsonResource
$this additional(array $data)

Add additional meta data to the resource response.

from JsonResource
void withResponse(Request $request, JsonResponse $response)

Customize the response for a request.

from JsonResource
static void wrap(string $value)

Set the string that should wrap the outer-most resource array.

from JsonResource
static void withoutWrapping()

Disable wrapping of the outer-most resource array.

from JsonResource
JsonResponse response(Request|null $request = null)

Transform the resource into an HTTP response.

from JsonResource
Response toResponse(Request $request)

Create an HTTP response that represents the object.

from ResourceCollection
array jsonSerialize()

Prepare the resource for JSON serialization.

from JsonResource
mixed collectResource(mixed $resource)

Map the given collection resource into its individual resources.

from CollectsResources
string|null collects()

Get the resource that this resource collects.

from CollectsResources
ArrayIterator getIterator()

Get an iterator for the resource collection.

from CollectsResources
$this preserveQuery()

Indicate that all current query parameters should be appended to pagination links.

from ResourceCollection
$this withQuery(array $query)

Specify the query string parameters that should be present on pagination links.

from ResourceCollection
int count()

Return the count of items in the resource collection.

from ResourceCollection
JsonResponse preparePaginatedResponse(Request $request)

Create a paginate-aware HTTP response.

from ResourceCollection

Details

protected array filter(array $data)

Filter the given data, removing any optional values.

Parameters

array $data

Return Value

array

protected array mergeData(array $data, int $index, array $merge, bool $numericKeys)

Merge the given data in at the given index.

Parameters

array $data
int $index
array $merge
bool $numericKeys

Return Value

array

protected array removeMissingValues(array $data)

Remove the missing values from the filtered data.

Parameters

array $data

Return Value

array

protected MissingValue|mixed when(bool $condition, mixed $value, mixed $default = null)

Retrieve a value based on a given condition.

Parameters

bool $condition
mixed $value
mixed $default

Return Value

MissingValue|mixed

protected MergeValue|mixed merge(mixed $value)

Merge a value into the array.

Parameters

mixed $value

Return Value

MergeValue|mixed

protected MergeValue|mixed mergeWhen(bool $condition, mixed $value)

Merge a value based on a given condition.

Parameters

bool $condition
mixed $value

Return Value

MergeValue|mixed

protected MergeValue attributes(array $attributes)

Merge the given attributes.

Parameters

array $attributes

Return Value

MergeValue

protected MissingValue|mixed whenLoaded(string $relationship, mixed $value = null, mixed $default = null)

Retrieve a relationship if it has been loaded.

Parameters

string $relationship
mixed $value
mixed $default

Return Value

MissingValue|mixed

protected MissingValue|mixed whenPivotLoaded(string $table, mixed $value, mixed $default = null)

Execute a callback if the given pivot table has been loaded.

Parameters

string $table
mixed $value
mixed $default

Return Value

MissingValue|mixed

protected MissingValue|mixed whenPivotLoadedAs(string $accessor, string $table, mixed $value, mixed $default = null)

Execute a callback if the given pivot table with a custom accessor has been loaded.

Parameters

string $accessor
string $table
mixed $value
mixed $default

Return Value

MissingValue|mixed

protected mixed transform(mixed $value, callable $callback, mixed $default = null)

Transform the given value if it is present.

Parameters

mixed $value
callable $callback
mixed $default

Return Value

mixed

protected mixed forwardCallTo(mixed $object, string $method, array $parameters)

Forward a method call to the given object.

Parameters

mixed $object
string $method
array $parameters

Return Value

mixed

Exceptions

BadMethodCallException

static protected void throwBadMethodCallException(string $method)

Throw a bad method call exception for the given method.

Parameters

string $method

Return Value

void

Exceptions

BadMethodCallException

mixed getRouteKey()

Get the value of the resource's route key.

Return Value

mixed

string getRouteKeyName()

Get the route key for the resource.

Return Value

string

void resolveRouteBinding(mixed $value)

Retrieve the model for a bound value.

Parameters

mixed $value

Return Value

void

Exceptions

Exception

bool offsetExists(mixed $offset)

Determine if the given attribute exists.

Parameters

mixed $offset

Return Value

bool

mixed offsetGet(mixed $offset)

Get the value for a given offset.

Parameters

mixed $offset

Return Value

mixed

void offsetSet(mixed $offset, mixed $value)

Set the value for a given offset.

Parameters

mixed $offset
mixed $value

Return Value

void

void offsetUnset(mixed $offset)

Unset the value for a given offset.

Parameters

mixed $offset

Return Value

void

bool __isset(string $key)

Determine if an attribute exists on the resource.

Parameters

string $key

Return Value

bool

void __unset(string $key)

Unset an attribute on the resource.

Parameters

string $key

Return Value

void

mixed __get(string $key)

Dynamically get properties from the underlying resource.

Parameters

string $key

Return Value

mixed

mixed __call(string $method, array $parameters)

Dynamically pass method calls to the underlying resource.

Parameters

string $method
array $parameters

Return Value

mixed

void __construct(mixed $resource, string $collects)

Create a new anonymous resource collection.

Parameters

mixed $resource
string $collects

Return Value

void

static JsonResource make(mixed ...$parameters)

Create a new resource instance.

Parameters

mixed ...$parameters

Return Value

JsonResource

static AnonymousResourceCollection collection(mixed $resource)

Create new anonymous resource collection.

Parameters

mixed $resource

Return Value

AnonymousResourceCollection

array resolve(Request|null $request = null)

Resolve the resource to an array.

Parameters

Request|null $request

Return Value

array

array toArray(Request $request)

Transform the resource into a JSON array.

Parameters

Request $request

Return Value

array

array with(Request $request)

Get any additional data that should be returned with the resource array.

Parameters

Request $request

Return Value

array

$this additional(array $data)

Add additional meta data to the resource response.

Parameters

array $data

Return Value

$this

void withResponse(Request $request, JsonResponse $response)

Customize the response for a request.

Parameters

Request $request
JsonResponse $response

Return Value

void

static void wrap(string $value)

Set the string that should wrap the outer-most resource array.

Parameters

string $value

Return Value

void

static void withoutWrapping()

Disable wrapping of the outer-most resource array.

Return Value

void

JsonResponse response(Request|null $request = null)

Transform the resource into an HTTP response.

Parameters

Request|null $request

Return Value

JsonResponse

Response toResponse(Request $request)

Create an HTTP response that represents the object.

Parameters

Request $request

Return Value

Response

array jsonSerialize()

Prepare the resource for JSON serialization.

Return Value

array

protected mixed collectResource(mixed $resource)

Map the given collection resource into its individual resources.

Parameters

mixed $resource

Return Value

mixed

protected string|null collects()

Get the resource that this resource collects.

Return Value

string|null

ArrayIterator getIterator()

Get an iterator for the resource collection.

Return Value

ArrayIterator

$this preserveQuery()

Indicate that all current query parameters should be appended to pagination links.

Return Value

$this

$this withQuery(array $query)

Specify the query string parameters that should be present on pagination links.

Parameters

array $query

Return Value

$this

int count()

Return the count of items in the resource collection.

Return Value

int

protected JsonResponse preparePaginatedResponse(Request $request)

Create a paginate-aware HTTP response.

Parameters

Request $request

Return Value

JsonResponse

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/6.x/Illuminate/Http/Resources/Json/AnonymousResourceCollection.html