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
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 resource instance.
Create a new anonymous resource collection.
Create a new resource collection instance.
Get the JSON serialization options that should be applied to the resource response.
Set the string that should wrap the outer-most resource array.
Map the given collection resource into its individual resources.
Indicate that all current query parameters should be appended to pagination links.
Specify the query string parameters that should be present on pagination links.
Return the count of items in the resource collection.
Details
protected array
mergeData(array $data, int $index, array $merge, bool $numericKeys)
Merge the given data in at the given index.
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
mergeWhen(bool $condition, mixed $value, mixed $default = null)
Merge a value if the given condition is truthy.
protected MergeValue|mixed
mergeUnless(bool $condition, mixed $value, mixed $default = null)
Merge a value unless the given condition is truthy.
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.
MissingValue|mixed
whenAggregated(string $relationship, string $column, string $aggregate, mixed $value = null, mixed $default = null)
Retrieve a relationship aggregated value if it exists.
MissingValue|mixed
whenExistsLoaded(string $relationship, mixed $value = null, mixed $default = null)
Retrieve a relationship existence check 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 never
throwBadMethodCallException(string $method)
Throw a bad method call exception for the given method.
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.
static AnonymousResourceCollection
collection(mixed $resource)
Create a new anonymous resource collection.
static protected AnonymousResourceCollection
newCollection(mixed $resource)
Create a new resource collection instance.
array|Arrayable|JsonSerializable
toArray(Request $request)
Transform the resource into a JSON array.
array
with(Request $request)
Get any additional data that should be returned with the resource array.
int
jsonOptions()
Get the JSON serialization options that should be applied to the resource response.
protected mixed
collectResource(mixed $resource)
Map the given collection resource into its individual resources.
$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.
protected JsonResponse
preparePaginatedResponse(Request $request)
Create a paginate-aware HTTP response.