trait ConditionallyLoadsAttributes (View source)

Properties

static protected array<class-string, bool> $cachedPreserveKeysAttributes

The cached preserve keys attribute values.

Methods

array
filter(array $data)

Filter the given data, removing any optional values.

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

Merge the given data in at the given index.

array
removeMissingValues(array $data)

Remove the missing values from the filtered data.

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

Retrieve a value if the given "condition" is truthy.

MissingValue|mixed
unless(bool $condition, mixed $value, mixed $default = new MissingValue())

Retrieve a value if the given "condition" is falsy.

MergeValue|mixed
merge(mixed $value)

Merge a value into the array.

MergeValue|mixed
mergeWhen(bool $condition, mixed $value, mixed $default = new MissingValue())

Merge a value if the given condition is truthy.

MergeValue|mixed
mergeUnless(bool $condition, mixed $value, mixed $default = new MissingValue())

Merge a value unless the given condition is truthy.

attributes(array $attributes)

Merge the given attributes.

MissingValue|mixed
whenHas(string $attribute, mixed $value = null, mixed $default = new MissingValue())

Retrieve an attribute if it exists on the resource.

MissingValue|mixed
whenNull(mixed $value, mixed $default = new MissingValue())

Retrieve a model attribute if it is null.

MissingValue|mixed
whenNotNull(mixed $value, mixed $default = new MissingValue())

Retrieve a model attribute if it is not null.

MissingValue|mixed
whenAppended(string $attribute, mixed $value = null, mixed $default = new MissingValue())

Retrieve an accessor when it has been appended.

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

Retrieve a relationship if it has been loaded.

MissingValue|mixed
whenCounted(string $relationship, mixed $value = null, mixed $default = new MissingValue())

Retrieve a relationship count if it exists.

MissingValue|mixed
whenAggregated(string $relationship, string $column, string $aggregate, mixed $value = null, mixed $default = new MissingValue())

Retrieve a relationship aggregated value if it exists.

MissingValue|mixed
whenExistsLoaded(string $relationship, mixed $value = null, mixed $default = new MissingValue())

Retrieve a relationship existence check if it exists.

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

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

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

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

bool
hasPivotLoaded(string $table)

Determine if the resource has the specified pivot table loaded.

bool
hasPivotLoadedAs(string $accessor, string $table)

Determine if the resource has the specified pivot table loaded with a custom accessor.

mixed
transform(mixed $value, callable $callback, mixed $default = new MissingValue())

Transform the given value if it is present.

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 = new MissingValue())

Retrieve a value if the given "condition" is truthy.

Parameters

bool $condition
mixed $value
mixed $default

Return Value

MissingValue|mixed

MissingValue|mixed unless(bool $condition, mixed $value, mixed $default = new MissingValue())

Retrieve a value if the given "condition" is falsy.

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, mixed $default = new MissingValue())

Merge a value if the given condition is truthy.

Parameters

bool $condition
mixed $value
mixed $default

Return Value

MergeValue|mixed

protected MergeValue|mixed mergeUnless(bool $condition, mixed $value, mixed $default = new MissingValue())

Merge a value unless the given condition is truthy.

Parameters

bool $condition
mixed $value
mixed $default

Return Value

MergeValue|mixed

protected MergeValue attributes(array $attributes)

Merge the given attributes.

Parameters

array $attributes

Return Value

MergeValue

MissingValue|mixed whenHas(string $attribute, mixed $value = null, mixed $default = new MissingValue())

Retrieve an attribute if it exists on the resource.

Parameters

string $attribute
mixed $value
mixed $default

Return Value

MissingValue|mixed

protected MissingValue|mixed whenNull(mixed $value, mixed $default = new MissingValue())

Retrieve a model attribute if it is null.

Parameters

mixed $value
mixed $default

Return Value

MissingValue|mixed

protected MissingValue|mixed whenNotNull(mixed $value, mixed $default = new MissingValue())

Retrieve a model attribute if it is not null.

Parameters

mixed $value
mixed $default

Return Value

MissingValue|mixed

protected MissingValue|mixed whenAppended(string $attribute, mixed $value = null, mixed $default = new MissingValue())

Retrieve an accessor when it has been appended.

Parameters

string $attribute
mixed $value
mixed $default

Return Value

MissingValue|mixed

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

Retrieve a relationship if it has been loaded.

Parameters

string $relationship
mixed $value
mixed $default

Return Value

MissingValue|mixed

MissingValue|mixed whenCounted(string $relationship, mixed $value = null, mixed $default = new MissingValue())

Retrieve a relationship count if it exists.

Parameters

string $relationship
mixed $value
mixed $default

Return Value

MissingValue|mixed

MissingValue|mixed whenAggregated(string $relationship, string $column, string $aggregate, mixed $value = null, mixed $default = new MissingValue())

Retrieve a relationship aggregated value if it exists.

Parameters

string $relationship
string $column
string $aggregate
mixed $value
mixed $default

Return Value

MissingValue|mixed

MissingValue|mixed whenExistsLoaded(string $relationship, mixed $value = null, mixed $default = new MissingValue())

Retrieve a relationship existence check if it exists.

Parameters

string $relationship
mixed $value
mixed $default

Return Value

MissingValue|mixed

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

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 = new MissingValue())

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 bool hasPivotLoaded(string $table)

Determine if the resource has the specified pivot table loaded.

Parameters

string $table

Return Value

bool

protected bool hasPivotLoadedAs(string $accessor, string $table)

Determine if the resource has the specified pivot table loaded with a custom accessor.

Parameters

string $accessor
string $table

Return Value

bool

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

Transform the given value if it is present.

Parameters

mixed $value
callable $callback
mixed $default

Return Value

mixed

Laravel Cloud is the best place to deploy Laravel, Nuxt, Express, Hono, Node.js, Bun, Go, Flask, Python, and more, with dedicated infrastructure available on AWS through Laravel Private Cloud.