class JsonResource implements ArrayAccess, JsonSerializable, Responsable, UrlRoutable (View source)
ConditionallyLoadsAttributes | |
DelegatesToResource | |
ForwardsCalls |
mixed | $resource | The resource instance. | |
array | $with | The additional data that should be added to the top-level resource array. | |
array | $additional | The additional meta data that should be added to the resource response. | |
static string | $wrap | The "data" wrapper that should be applied. |
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 | 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 | 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, 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 |
mixed | __call(string $method, array $parameters) Dynamically pass method calls to the underlying resource. | from DelegatesToResource |
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 new anonymous resource collection. | |
array | resolve(Request|null $request = null) Resolve the resource to an array. | |
array | toArray(Request $request) Transform the resource into an 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. | |
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. |
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 based on a given condition.
Merge a value into the array.
Merge a value based on a given condition.
Merge the given attributes.
Retrieve an accessor when it has been appended.
Retrieve a relationship if it has been loaded.
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.
Transform the given value if it is present.
Forward a method call to the given object.
Throw a bad method call exception for the given method.
Get the value of the resource's route key.
Get the route key for the resource.
Retrieve the model for a bound value.
Retrieve the model for a bound value.
Determine if the given attribute exists.
Get the value for a given offset.
Set the value for a given offset.
Unset the value for a given offset.
Determine if an attribute exists on the resource.
Unset an attribute on the resource.
Dynamically get properties from the underlying resource.
Dynamically pass method calls to the underlying resource.
Create a new resource instance.
Create a new resource instance.
Create new anonymous resource collection.
Resolve the resource to an array.
Transform the resource into an array.
Convert the model instance to JSON.
Get any additional data that should be returned with the resource array.
Add additional meta data to the resource response.
Customize the response for a request.
Set the string that should wrap the outer-most resource array.
Disable wrapping of the outer-most resource array.
Transform the resource into an HTTP response.
Create an HTTP response that represents the object.
Prepare the resource for JSON serialization.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/8.x/Illuminate/Http/Resources/Json/JsonResource.html