On this page
ResourceCollection
class ResourceCollection extends JsonResource implements Countable, IteratorAggregate (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. |
from JsonResource |
string | $collects | The resource that this resource collects. |
|
Collection | $collection | The mapped collection instance. |
|
protected bool | $preserveAllQueryParameters | Indicates if all existing request query parameters should be added to pagination links. |
|
protected array|null | $queryParameters | The query parameters that should be added to the pagination links. |
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 if the given "condition" is truthy. |
from ConditionallyLoadsAttributes |
MissingValue|mixed | unless(bool $condition, mixed $value, mixed $default = null) Retrieve a value if the given "condition" is falsy. |
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 if the given condition is truthy. |
from ConditionallyLoadsAttributes |
MergeValue|mixed | mergeUnless(bool $condition, mixed $value) Merge a value unless the given condition is truthy. |
from ConditionallyLoadsAttributes |
MergeValue | attributes(array $attributes) Merge the given attributes. |
from ConditionallyLoadsAttributes |
MissingValue|mixed | whenHas(string $attribute, mixed $value = null, mixed $default = null) Retrieve an attribute if it exists on the resource. |
from ConditionallyLoadsAttributes |
MissingValue|mixed | whenNull(mixed $value, mixed $default = null) Retrieve a model attribute if it is null. |
from ConditionallyLoadsAttributes |
MissingValue|mixed | whenNotNull(mixed $value, mixed $default = null) Retrieve a model attribute if it is not null. |
from ConditionallyLoadsAttributes |
MissingValue|mixed | whenAppended(string $attribute, mixed $value = null, mixed $default = null) Retrieve an accessor when it has been appended. |
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 | whenCounted(string $relationship, mixed $value = null, mixed $default = null) Retrieve a relationship count if it exists. |
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 |
bool | hasPivotLoaded(string $table) Determine if the resource has the specified pivot table loaded. |
from ConditionallyLoadsAttributes |
bool | hasPivotLoadedAs(string $accessor, string $table) Determine if the resource has the specified pivot table loaded with a custom accessor. |
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 |
mixed | forwardDecoratedCallTo(mixed $object, string $method, array $parameters) Forward a method call to the given object, returning $this if the forwarded call returned itself. |
from ForwardsCalls |
static void | throwBadMethodCallException(string $method) Throw a bad method call exception for the given method. |
from ForwardsCalls |
static void | macro(string $name, object|callable $macro) Register a custom macro. |
from Macroable |
static void | mixin(object $mixin, bool $replace = true) Mix another object into the class. |
from Macroable |
static bool | hasMacro(string $name) Checks if macro is registered. |
from Macroable |
static void | flushMacros() Flush the existing macros. |
from Macroable |
static mixed | __callStatic(string $method, array $parameters) Dynamically handle calls to the class. |
from Macroable |
mixed | __call(string $method, array $parameters) Dynamically handle calls to the class. |
from Macroable |
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, string|null $field = null) Retrieve the model for a bound value. |
from DelegatesToResource |
void | resolveChildRouteBinding(string $childType, mixed $value, string|null $field = null) 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 |
void | __construct(mixed $resource) Create a new resource instance. |
|
static JsonResource | make(mixed ...$parameters) Create a new resource instance. |
from JsonResource |
static AnonymousResourceCollection | collection(mixed $resource) Create a new anonymous resource collection. |
from JsonResource |
static AnonymousResourceCollection | newCollection(mixed $resource) Create a new resource collection instance. |
from JsonResource |
array | resolve(Request|null $request = null) Resolve the resource to an array. |
from JsonResource |
array|Arrayable|JsonSerializable | toArray(Request $request) Transform the resource into a JSON array. |
|
string | toJson(int $options = 0) Convert the model instance to JSON. |
from JsonResource |
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 |
int | jsonOptions() Get the JSON serialization options that should be applied to the resource response. |
from CollectsResources |
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. |
|
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 |
Traversable | getIterator() Get an iterator for the resource collection. |
from CollectsResources |
$this | preserveQuery() Indicate that all current query parameters should be appended to pagination links. |
|
$this | withQuery(array $query) Specify the query string parameters that should be present on pagination links. |
|
int | count() Return the count of items in the resource collection. |
|
JsonResponse | preparePaginatedResponse(Request $request) Create a paginate-aware HTTP response. |
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 = null)
Retrieve a value if the given "condition" is truthy.
MissingValue|mixed unless(bool $condition, mixed $value, mixed $default = null)
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)
Merge a value if the given condition is truthy.
protected MergeValue|mixed mergeUnless(bool $condition, mixed $value)
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 = null)
Retrieve an attribute if it exists on the resource.
protected MissingValue|mixed whenNull(mixed $value, mixed $default = null)
Retrieve a model attribute if it is null.
protected MissingValue|mixed whenNotNull(mixed $value, mixed $default = null)
Retrieve a model attribute if it is not null.
protected MissingValue|mixed whenAppended(string $attribute, mixed $value = null, mixed $default = null)
Retrieve an accessor when it has been appended.
protected MissingValue|mixed whenLoaded(string $relationship, mixed $value = null, mixed $default = null)
Retrieve a relationship if it has been loaded.
MissingValue|mixed whenCounted(string $relationship, mixed $value = null, mixed $default = null)
Retrieve a relationship count if it exists.
protected MissingValue|mixed whenPivotLoaded(string $table, mixed $value, mixed $default = null)
Execute a callback if the given pivot table has been loaded.
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.
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 = null)
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 void 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.
void __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 toArray(Request $request)
Transform the resource into a JSON array.
string toJson(int $options = 0)
Convert the model instance to 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 response for a request.
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.
protected mixed collectResource(mixed $resource)
Map the given collection resource into its individual resources.
protected string|null collects()
Get the resource that this resource collects.
Traversable getIterator()
Get an iterator for the resource collection.
$this preserveQuery()
Indicate that all current query parameters should be appended to pagination links.
$this withQuery(array $query)
Specify the query string parameters that should be present on pagination links.
int count()
Return the count of items in the resource collection.
protected JsonResponse preparePaginatedResponse(Request $request)
Create a paginate-aware HTTP response.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/10.x/Illuminate/Http/Resources/Json/ResourceCollection.html