trait GuardsAttributes

Properties

protected array<int, string> $fillable

The attributes that are mass assignable.

protected string[] $guarded

The attributes that aren't mass assignable.

static protected array<class-string, list<string>> $guardableColumns

The actual columns that exist on the database and can be guarded.

static protected array<class-string, array{guarded: null|array<int, string>, propertyDefault: array<int, string>}> $guardConfigurations

The resolved guard configuration for each model class.

Methods

void
initializeGuardsAttributes()

Initialize the GuardsAttributes trait.

static array
guardConfiguration()

Resolve the nearest guard configuration for the model class.

static array|null
guardConfigurationFromTraits(array $traits)

Resolve guard configuration declared by traits at one class level.

array
getFillable()

Get the fillable attributes for the model.

fillable(array $fillable)

Set the fillable attributes for the model.

mergeFillable(array $fillable)

Merge new fillable attributes with existing fillable attributes on the model.

array
getGuarded()

Get the guarded attributes for the model.

guard(array $guarded)

Set the guarded attributes for the model.

mergeGuarded(array $guarded)

Merge new guarded attributes with existing guarded attributes on the model.

static void
unguard(bool $state = true)

Disable all mass assignable restrictions.

static void
reguard()

Enable the mass assignment restrictions.

static bool
isUnguarded()

Determine if the current state is "unguarded".

static mixed
unguarded(callable $callback)

Run the given callable while being unguarded.

bool
isFillable(string $key)

Determine if the given attribute may be mass assigned.

bool
isGuarded(string $key)

Determine if the given key is guarded.

bool
isGuardableColumn(string $key)

Determine if the given column is a valid, guardable column.

bool
totallyGuarded()

Determine if the model is totally guarded.

array
fillableFromArray(array $attributes)

Get the fillable attributes of a given array.

Details

at line 48
void initializeGuardsAttributes()

Initialize the GuardsAttributes trait.

Return Value

void

at line 72
static protected array guardConfiguration()

Resolve the nearest guard configuration for the model class.

Return Value

array

at line 126
static protected array|null guardConfigurationFromTraits(array $traits)

Resolve guard configuration declared by traits at one class level.

Parameters

array $traits

Return Value

array|null

at line 149
array getFillable()

Get the fillable attributes for the model.

Return Value

array

at line 160
GuardsAttributes fillable(array $fillable)

Set the fillable attributes for the model.

Parameters

array $fillable

Return Value

GuardsAttributes

at line 173
GuardsAttributes mergeFillable(array $fillable)

Merge new fillable attributes with existing fillable attributes on the model.

Parameters

array $fillable

Return Value

GuardsAttributes

at line 189
array getGuarded()

Get the guarded attributes for the model.

Return Value

array

at line 202
GuardsAttributes guard(array $guarded)

Set the guarded attributes for the model.

Parameters

array $guarded

Return Value

GuardsAttributes

at line 215
GuardsAttributes mergeGuarded(array $guarded)

Merge new guarded attributes with existing guarded attributes on the model.

Parameters

array $guarded

Return Value

GuardsAttributes

at line 227
static void unguard(bool $state = true)

Disable all mass assignable restrictions.

Uses Context for coroutine-safe state management.

Parameters

bool $state

Return Value

void

at line 235
static void reguard()

Enable the mass assignment restrictions.

Return Value

void

at line 243
static bool isUnguarded()

Determine if the current state is "unguarded".

Return Value

bool

at line 259
static mixed unguarded(callable $callback)

Run the given callable while being unguarded.

Uses Context for coroutine-safe state management, ensuring concurrent requests don't interfere with each other's guarding state.

Parameters

callable $callback

Return Value

mixed

at line 278
bool isFillable(string $key)

Determine if the given attribute may be mass assigned.

Parameters

string $key

Return Value

bool

at line 306
bool isGuarded(string $key)

Determine if the given key is guarded.

Parameters

string $key

Return Value

bool

at line 320
protected bool isGuardableColumn(string $key)

Determine if the given column is a valid, guardable column.

Parameters

string $key

Return Value

bool

at line 344
bool totallyGuarded()

Determine if the model is totally guarded.

Return Value

bool

at line 355
protected array fillableFromArray(array $attributes)

Get the fillable attributes of a given array.

Parameters

array $attributes

Return Value

array