Resource
class Resource extends JsonResource (View source)
Traits
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 |
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 based on a given condition.
Merge a value into the array.
Merge a value based on a given condition.
Merge the given attributes.
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.
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.
Dynamically pass method calls to the underlying resource.
Create new anonymous resource collection.
Set the string that should wrap the outer-most resource array.
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 based on a given condition.
protected MergeValue|mixed
merge(mixed $value)
Merge a value into the array.
protected MergeValue|mixed
mergeWhen(bool $condition, mixed $value)
Merge a value based on a given condition.
protected MergeValue
attributes(array $attributes)
Merge the given attributes.
protected MissingValue|mixed
whenLoaded(string $relationship, mixed $value = null, mixed $default = null)
Retrieve a relationship if it has been loaded.
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 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.
static protected void
throwBadMethodCallException(string $method)
Throw a bad method call exception for the given method.
mixed
getRouteKey()
Get the value of the resource's route key.
string
getRouteKeyName()
Get the route key for the resource.
void
resolveRouteBinding(mixed $value)
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.
mixed
__call(string $method, array $parameters)
Dynamically pass method calls to 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 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.
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.