class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable (View source)

Traits

Constants

CREATED_AT

The name of the "created at" column.

UPDATED_AT

The name of the "updated at" column.

Properties

protected array $attributes The model's attributes. from HasAttributes
protected array $original The model attribute's original state. from HasAttributes
protected array $changes The changed model attributes. from HasAttributes
protected array $casts The attributes that should be cast to native types. from HasAttributes
protected array $dates The attributes that should be mutated to dates. from HasAttributes
protected string $dateFormat The storage format of the model's date columns. from HasAttributes
protected array $appends The accessors to append to the model's array form. from HasAttributes
static bool $snakeAttributes Indicates whether attributes are snake cased on arrays. from HasAttributes
static protected array $mutatorCache The cache of the mutated attributes for each class. from HasAttributes
protected array $dispatchesEvents The event map for the model. from HasEvents
protected array $observables User exposed observable events. from HasEvents
protected array $relations The loaded relationships for the model. from HasRelationships
protected array $touches The relationships that should be touched on save. from HasRelationships
static array $manyMethods The many to many relationship methods. from HasRelationships
bool $timestamps Indicates if the model should be timestamped. from HasTimestamps
protected array $hidden The attributes that should be hidden for serialization. from HidesAttributes
protected array $visible The attributes that should be visible in serialization. from HidesAttributes
protected array $fillable The attributes that are mass assignable. from GuardsAttributes
protected array $guarded The attributes that aren't mass assignable. from GuardsAttributes
static protected bool $unguarded Indicates if all mass assignment is enabled. from GuardsAttributes
protected string $connection The connection name for the model.
protected string $table The table associated with the model.
protected string $primaryKey The primary key for the model.
protected string $keyType The "type" of the auto-incrementing ID.
bool $incrementing Indicates if the IDs are auto-incrementing.
protected array $with The relations to eager load on every query.
protected array $withCount The relationship counts that should be eager loaded on every query.
protected int $perPage The number of models to return for pagination.
bool $exists Indicates if the model exists.
bool $wasRecentlyCreated Indicates if the model was inserted during the current request lifecycle.
static protected ConnectionResolverInterface $resolver The connection resolver instance.
static protected Dispatcher $dispatcher The event dispatcher instance.
static protected array $booted The array of booted models.
static protected array $globalScopes The array of global scopes on the model.
static protected array $ignoreOnTouch The list of models classes that should not be affected with touch.

Methods

array
attributesToArray()

Convert the model's attributes to an array.

array
addDateAttributesToArray(array $attributes)

Add the date attributes to the attributes array.

array
addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)

Add the mutated attributes to the attributes array.

array
addCastAttributesToArray(array $attributes, array $mutatedAttributes)

Add the casted attributes to the attributes array.

array
getArrayableAttributes()

Get an attribute array of all arrayable attributes.

array
getArrayableAppends()

Get all of the appendable values that are arrayable.

array
relationsToArray()

Get the model's relationships in array form.

array
getArrayableRelations()

Get an attribute array of all arrayable relations.

array
getArrayableItems(array $values)

Get an attribute array of all arrayable values.

mixed
getAttribute(string $key)

Get an attribute from the model.

mixed
getAttributeValue(string $key)

Get a plain attribute (not a relationship).

mixed
getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

mixed
getRelationValue(string $key)

Get a relationship.

mixed
getRelationshipFromMethod(string $method)

Get a relationship value from a method.

bool
hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

mixed
mutateAttribute(string $key, mixed $value)

Get the value of an attribute using its mutator.

mixed
mutateAttributeForArray(string $key, mixed $value)

Get the value of an attribute using its mutator for array conversion.

mixed
castAttribute(string $key, mixed $value)

Cast an attribute to a native PHP type.

string
getCastType(string $key)

Get the type of cast for a model attribute.

bool
isCustomDateTimeCast(string $cast)

Determine if the cast type is a custom date time cast.

mixed
setAttribute(string $key, mixed $value)

Set a given attribute on the model.

bool
hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

mixed
setMutatedAttributeValue(string $key, mixed $value)

Set the value of an attribute using its mutator.

bool
isDateAttribute(string $key)

Determine if the given attribute is a date or date castable.

$this
fillJsonAttribute(string $key, mixed $value)

Set a given JSON attribute on the model.

$this
getArrayAttributeWithValue(string $path, string $key, mixed $value)

Get an array attribute with the given key and value set.

array
getArrayAttributeByKey(string $key)

Get an array attribute or return an empty array if it is not set.

string
castAttributeAsJson(string $key, mixed $value)

Cast the given attribute to JSON.

string
asJson(mixed $value)

Encode the given value as JSON.

mixed
fromJson(string $value, bool $asObject = false)

Decode the given JSON back into an array or object.

asDate(mixed $value)

Return a timestamp as DateTime object with time set to 00:00:00.

asDateTime(mixed $value)

Return a timestamp as DateTime object.

bool
isStandardDateFormat(string $value)

Determine if the given value is a standard date format.

string
fromDateTime(DateTime|int $value)

Convert a DateTime to a storable string.

int
asTimestamp(mixed $value)

Return a timestamp as unix timestamp.

string
serializeDate(DateTimeInterface $date)

Prepare a date for array / JSON serialization.

array
getDates()

Get the attributes that should be converted to dates.

string
getDateFormat()

Get the format for database stored dates.

$this
setDateFormat(string $format)

Set the date format used by the model.

bool
hasCast(string $key, array|string|null $types = null)

Determine whether an attribute should be cast to a native type.

array
getCasts()

Get the casts array.

bool
isDateCastable(string $key)

Determine whether a value is Date / DateTime castable for inbound manipulation.

bool
isJsonCastable(string $key)

Determine whether a value is JSON castable for inbound manipulation.

array
getAttributes()

Get all of the current attributes on the model.

$this
setRawAttributes(array $attributes, bool $sync = false)

Set the array of model attributes. No checking is done.

mixed|array
getOriginal(string|null $key = null, mixed $default = null)

Get the model's original attribute values.

array
only(array|mixed $attributes)

Get a subset of the model's attributes.

$this
syncOriginal()

Sync the original attributes with the current.

$this
syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

$this
syncChanges()

Sync the changed attributes.

bool
isDirty(array|string|null $attributes = null)

Determine if the model or given attribute(s) have been modified.

bool
isClean(array|string|null $attributes = null)

Determine if the model or given attribute(s) have remained the same.

bool
wasChanged(array|string|null $attributes = null)

Determine if the model or given attribute(s) have been modified.

bool
hasChanges(array $changes, array|string|null $attributes = null)

Determine if the given attributes were changed.

array
getDirty()

Get the attributes that have been changed since last sync.

array
getChanges()

Get the attributes that were changed.

bool
originalIsEquivalent(string $key, mixed $current)

Determine if the new and old values for a given key are equivalent.

$this
append(array|string $attributes)

Append attributes to query when building a query.

$this
setAppends(array $appends)

Set the accessors to append to model arrays.

array
getMutatedAttributes()

Get the mutated attributes for a given instance.

static void
cacheMutatedAttributes(string $class)

Extract and cache all the mutated attributes of a class.

static array
getMutatorMethods(mixed $class)

Get all of the attribute mutator methods.

static void
observe(object|array|string $classes)

Register observers with the model.

from HasEvents
void
registerObserver(object|string $class)

Register a single observer with the model.

from HasEvents
array
getObservableEvents()

Get the observable event names.

from HasEvents
$this
setObservableEvents(array $observables)

Set the observable event names.

from HasEvents
void
addObservableEvents(array|mixed $observables)

Add an observable event name.

from HasEvents
void
removeObservableEvents(array|mixed $observables)

Remove an observable event name.

from HasEvents
static void
registerModelEvent(string $event, Closure|string $callback)

Register a model event with the dispatcher.

from HasEvents
mixed
fireModelEvent(string $event, bool $halt = true)

Fire the given event for the model.

from HasEvents
mixed|null
fireCustomModelEvent(string $event, string $method)

Fire a custom model event for the given event.

from HasEvents
mixed
filterModelEventResults(mixed $result)

Filter the model event results.

from HasEvents
static void
retrieved(Closure|string $callback)

Register a retrieved model event with the dispatcher.

from HasEvents
static void
saving(Closure|string $callback)

Register a saving model event with the dispatcher.

from HasEvents
static void
saved(Closure|string $callback)

Register a saved model event with the dispatcher.

from HasEvents
static void
updating(Closure|string $callback)

Register an updating model event with the dispatcher.

from HasEvents
static void
updated(Closure|string $callback)

Register an updated model event with the dispatcher.

from HasEvents
static void
creating(Closure|string $callback)

Register a creating model event with the dispatcher.

from HasEvents
static void
created(Closure|string $callback)

Register a created model event with the dispatcher.

from HasEvents
static void
deleting(Closure|string $callback)

Register a deleting model event with the dispatcher.

from HasEvents
static void
deleted(Closure|string $callback)

Register a deleted model event with the dispatcher.

from HasEvents
static void
flushEventListeners()

Remove all of the event listeners for the model.

from HasEvents
static Dispatcher
getEventDispatcher()

Get the event dispatcher instance.

from HasEvents
static void
setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

from HasEvents
static void
unsetEventDispatcher()

Unset the event dispatcher for models.

from HasEvents
static mixed
addGlobalScope(Scope|Closure|string $scope, Closure $implementation = null)

Register a new global scope on the model.

static bool
hasGlobalScope(Scope|string $scope)

Determine if a model has a global scope.

static Scope|Closure|null
getGlobalScope(Scope|string $scope)

Get a global scope registered with the model.

array
getGlobalScopes()

Get the global scopes for this class instance.

hasOne(string $related, string $foreignKey = null, string $localKey = null)

Define a one-to-one relationship.

newHasOne(Builder $query, Model $parent, string $foreignKey, string $localKey)

Instantiate a new HasOne relationship.

morphOne(string $related, string $name, string $type = null, string $id = null, string $localKey = null)

Define a polymorphic one-to-one relationship.

newMorphOne(Builder $query, Model $parent, string $type, string $id, string $localKey)

Instantiate a new MorphOne relationship.

belongsTo(string $related, string $foreignKey = null, string $ownerKey = null, string $relation = null)

Define an inverse one-to-one or many relationship.

newBelongsTo(Builder $query, Model $child, string $foreignKey, string $ownerKey, string $relation)

Instantiate a new BelongsTo relationship.

morphTo(string $name = null, string $type = null, string $id = null, string $ownerKey = null)

Define a polymorphic, inverse one-to-one or many relationship.

morphEagerTo(string $name, string $type, string $id, string $ownerKey)

Define a polymorphic, inverse one-to-one or many relationship.

morphInstanceTo(string $target, string $name, string $type, string $id, string $ownerKey)

Define a polymorphic, inverse one-to-one or many relationship.

newMorphTo(Builder $query, Model $parent, string $foreignKey, string $ownerKey, string $type, string $relation)

Instantiate a new MorphTo relationship.

static string
getActualClassNameForMorph(string $class)

Retrieve the actual class name for a given morph class.

string
guessBelongsToRelation()

Guess the "belongs to" relationship name.

hasMany(string $related, string $foreignKey = null, string $localKey = null)

Define a one-to-many relationship.

newHasMany(Builder $query, Model $parent, string $foreignKey, string $localKey)

Instantiate a new HasMany relationship.

hasManyThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null, string|null $localKey = null, string|null $secondLocalKey = null)

Define a has-many-through relationship.

newHasManyThrough(Builder $query, Model $farParent, Model $throughParent, string $firstKey, string $secondKey, string $localKey, string $secondLocalKey)

Instantiate a new HasManyThrough relationship.

morphMany(string $related, string $name, string $type = null, string $id = null, string $localKey = null)

Define a polymorphic one-to-many relationship.

newMorphMany(Builder $query, Model $parent, string $type, string $id, string $localKey)

Instantiate a new MorphMany relationship.

belongsToMany(string $related, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null, string $relation = null)

Define a many-to-many relationship.

newBelongsToMany(Builder $query, Model $parent, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string $relationName = null)

Instantiate a new BelongsToMany relationship.

morphToMany(string $related, string $name, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null, bool $inverse = false)

Define a polymorphic many-to-many relationship.

newMorphToMany(Builder $query, Model $parent, string $name, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string $relationName = null, bool $inverse = false)

Instantiate a new MorphToMany relationship.

morphedByMany(string $related, string $name, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null)

Define a polymorphic, inverse many-to-many relationship.

string
guessBelongsToManyRelation()

Get the relationship name of the belongs to many.

string
joiningTable(string $related)

Get the joining table name for a many-to-many relation.

bool
touches(string $relation)

Determine if the model touches a given relation.

void
touchOwners()

Touch the owning relations of the model.

array
getMorphs(string $name, string $type, string $id)

Get the polymorphic relationship columns.

string
getMorphClass()

Get the class name for polymorphic relations.

mixed
newRelatedInstance(string $class)

Create a new model instance for a related model.

array
getRelations()

Get all the loaded relations for the instance.

mixed
getRelation(string $relation)

Get a specified relationship.

bool
relationLoaded(string $key)

Determine if the given relation is loaded.

$this
setRelation(string $relation, mixed $value)

Set the given relationship on the model.

$this
unsetRelation(string $relation)

Unset a loaded relationship.

$this
setRelations(array $relations)

Set the entire relations array on the model.

array
getTouchedRelations()

Get the relationships that are touched on save.

$this
setTouchedRelations(array $touches)

Set the relationships that are touched on save.

bool
touch()

Update the model's update timestamp.

void
updateTimestamps()

Update the creation and update timestamps.

$this
setCreatedAt(mixed $value)

Set the value of the "created at" attribute.

$this
setUpdatedAt(mixed $value)

Set the value of the "updated at" attribute.

freshTimestamp()

Get a fresh timestamp for the model.

string
freshTimestampString()

Get a fresh timestamp for the model.

bool
usesTimestamps()

Determine if the model uses timestamps.

string
getCreatedAtColumn()

Get the name of the "created at" column.

string
getUpdatedAtColumn()

Get the name of the "updated at" column.

array
getHidden()

Get the hidden attributes for the model.

$this
setHidden(array $hidden)

Set the hidden attributes for the model.

void
addHidden(array|string|null $attributes = null)

Add hidden attributes for the model.

array
getVisible()

Get the visible attributes for the model.

$this
setVisible(array $visible)

Set the visible attributes for the model.

void
addVisible(array|string|null $attributes = null)

Add visible attributes for the model.

$this
makeVisible(array|string $attributes)

Make the given, typically hidden, attributes visible.

$this
makeHidden(array|string $attributes)

Make the given, typically visible, attributes hidden.

array
getFillable()

Get the fillable attributes for the model.

$this
fillable(array $fillable)

Set the fillable attributes for the model.

array
getGuarded()

Get the guarded attributes for the model.

$this
guard(array $guarded)

Set the guarded attributes for 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 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
totallyGuarded()

Determine if the model is totally guarded.

array
fillableFromArray(array $attributes)

Get the fillable attributes of a given array.

void
__construct(array $attributes = [])

Create a new Eloquent model instance.

void
bootIfNotBooted()

Check if the model needs to be booted and if so, do it.

static void
boot()

The "booting" method of the model.

static void
bootTraits()

Boot all of the bootable traits on the model.

static void
clearBootedModels()

Clear the list of booted models so they will be re-booted.

static void
withoutTouching(callable $callback)

Disables relationship model touching for the current class during given callback scope.

static void
withoutTouchingOn(array $models, callable $callback)

Disables relationship model touching for the given model classes during given callback scope.

static bool
isIgnoringTouch(string|null $class = null)

Determine if the given model is ignoring touches.

$this
fill(array $attributes)

Fill the model with an array of attributes.

$this
forceFill(array $attributes)

Fill the model with an array of attributes. Force mass assignment.

string
qualifyColumn(string $column)

Qualify the given column name by the model's table.

string
removeTableFromKey(string $key)

Remove the table name from a given key.

newInstance(array $attributes = [], bool $exists = false)

Create a new instance of the given model.

newFromBuilder(array $attributes = [], string|null $connection = null)

Create a new model instance that is existing.

static Builder
on(string|null $connection = null)

Begin querying the model on a given connection.

static Builder
onWriteConnection()

Begin querying the model on the write connection.

static Collection|Model[]
all(array|mixed $columns = ['*'])

Get all of the models from the database.

static Builder|Model
with(array|string $relations)

Begin querying a model with eager loading.

$this
load(array|string $relations)

Eager load relations on the model.

$this
loadMissing(array|string $relations)

Eager load relations on the model if they are not already eager loaded.

int
increment(string $column, float|int $amount = 1, array $extra = [])

Increment a column's value by a given amount.

int
decrement(string $column, float|int $amount = 1, array $extra = [])

Decrement a column's value by a given amount.

int
incrementOrDecrement(string $column, float|int $amount, array $extra, string $method)

Run the increment or decrement method on the model.

void
incrementOrDecrementAttributeValue(string $column, float|int $amount, array $extra, string $method)

Increment the underlying attribute value and sync with original.

bool
update(array $attributes = [], array $options = [])

Update the model in the database.

bool
push()

Save the model and all of its relationships.

bool
save(array $options = [])

Save the model to the database.

bool
saveOrFail(array $options = [])

Save the model to the database using transaction.

void
finishSave(array $options)

Perform any actions that are necessary after the model is saved.

bool
performUpdate(Builder $query)

Perform a model update operation.

setKeysForSaveQuery(Builder $query)

Set the keys for a save update query.

mixed
getKeyForSaveQuery()

Get the primary key value for a save query.

bool
performInsert(Builder $query)

Perform a model insert operation.

void
insertAndSetId(Builder $query, array $attributes)

Insert the given attributes and set the ID on the model.

static int
destroy(array|int $ids)

Destroy the models for the given IDs.

bool|null
delete()

Delete the model from the database.

bool|null
forceDelete()

Force a hard delete on a soft deleted model.

void
performDeleteOnModel()

Perform the actual delete query on this model instance.

static Builder
query()

Begin querying the model.

newQuery()

Get a new query builder for the model's table.

newModelQuery()

Get a new query builder that doesn't have any global scopes or eager loading.

newQueryWithoutRelationships()

Get a new query builder with no relationships loaded.

registerGlobalScopes(Builder $builder)

Register the global scopes for this builder instance.

newQueryWithoutScopes()

Get a new query builder that doesn't have any global scopes.

newQueryWithoutScope(Scope|string $scope)

Get a new query instance without a given scope.

newQueryForRestoration(array|int $ids)

Get a new query to restore one or more models by their queueable IDs.

newEloquentBuilder(Builder $query)

Create a new Eloquent query builder for the model.

newBaseQueryBuilder()

Get a new query builder instance for the connection.

newCollection(array $models = [])

Create a new Eloquent Collection instance.

newPivot(Model $parent, array $attributes, string $table, bool $exists, string|null $using = null)

Create a new pivot model instance.

array
toArray()

Convert the model instance to an array.

string
toJson(int $options)

Convert the model instance to JSON.

array
jsonSerialize()

Convert the object into something JSON serializable.

Model|null
fresh(array|string $with = [])

Reload a fresh model instance from the database.

$this
refresh()

Reload the current model instance with fresh attributes from the database.

replicate(array $except = null)

Clone the model into a new, non-existing instance.

bool
is(Model|null $model)

Determine if two models have the same ID and belong to the same table.

bool
isNot(Model|null $model)

Determine if two models are not the same.

getConnection()

Get the database connection for the model.

string
getConnectionName()

Get the current connection name for the model.

$this
setConnection(string $name)

Set the connection associated with the model.

static Connection
resolveConnection(string|null $connection = null)

Resolve a connection instance.

getConnectionResolver()

Get the connection resolver instance.

static void
setConnectionResolver(ConnectionResolverInterface $resolver)

Set the connection resolver instance.

static void
unsetConnectionResolver()

Unset the connection resolver for models.

string
getTable()

Get the table associated with the model.

$this
setTable(string $table)

Set the table associated with the model.

string
getKeyName()

Get the primary key for the model.

$this
setKeyName(string $key)

Set the primary key for the model.

string
getQualifiedKeyName()

Get the table qualified key name.

string
getKeyType()

Get the auto-incrementing key type.

$this
setKeyType(string $type)

Set the data type for the primary key.

bool
getIncrementing()

Get the value indicating whether the IDs are incrementing.

$this
setIncrementing(bool $value)

Set whether IDs are incrementing.

mixed
getKey()

Get the value of the model's primary key.

mixed
getQueueableId()

Get the queueable identity for the entity.

array
getQueueableRelations()

Get the queueable relationships for the entity.

string|null
getQueueableConnection()

Get the queueable connection for the entity.

mixed
getRouteKey()

Get the value of the model's route key.

string
getRouteKeyName()

Get the route key for the model.

Model|null
resolveRouteBinding(mixed $value)

Retrieve the model for a bound value.

string
getForeignKey()

Get the default foreign key name for the model.

int
getPerPage()

Get the number of models to return per page.

$this
setPerPage(int $perPage)

Set the number of models to return per page.

mixed
__get(string $key)

Dynamically retrieve attributes on the model.

void
__set(string $key, mixed $value)

Dynamically set attributes on the model.

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 or relation exists on the model.

void
__unset(string $key)

Unset an attribute on the model.

mixed
__call(string $method, array $parameters)

Handle dynamic method calls into the model.

static mixed
__callStatic(string $method, array $parameters)

Handle dynamic static method calls into the method.

string
__toString()

Convert the model to its string representation.

void
__wakeup()

When a model is being unserialized, check if it needs to be booted.

Details

array attributesToArray()

Convert the model's attributes to an array.

Return Value

array

protected array addDateAttributesToArray(array $attributes)

Add the date attributes to the attributes array.

Parameters

array $attributes

Return Value

array

protected array addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)

Add the mutated attributes to the attributes array.

Parameters

array $attributes
array $mutatedAttributes

Return Value

array

protected array addCastAttributesToArray(array $attributes, array $mutatedAttributes)

Add the casted attributes to the attributes array.

Parameters

array $attributes
array $mutatedAttributes

Return Value

array

protected array getArrayableAttributes()

Get an attribute array of all arrayable attributes.

Return Value

array

protected array getArrayableAppends()

Get all of the appendable values that are arrayable.

Return Value

array

array relationsToArray()

Get the model's relationships in array form.

Return Value

array

protected array getArrayableRelations()

Get an attribute array of all arrayable relations.

Return Value

array

protected array getArrayableItems(array $values)

Get an attribute array of all arrayable values.

Parameters

array $values

Return Value

array

mixed getAttribute(string $key)

Get an attribute from the model.

Parameters

string $key

Return Value

mixed

mixed getAttributeValue(string $key)

Get a plain attribute (not a relationship).

Parameters

string $key

Return Value

mixed

protected mixed getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

Parameters

string $key

Return Value

mixed

mixed getRelationValue(string $key)

Get a relationship.

Parameters

string $key

Return Value

mixed

protected mixed getRelationshipFromMethod(string $method)

Get a relationship value from a method.

Parameters

string $method

Return Value

mixed

Exceptions

LogicException

bool hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

Parameters

string $key

Return Value

bool

protected mixed mutateAttribute(string $key, mixed $value)

Get the value of an attribute using its mutator.

Parameters

string $key
mixed $value

Return Value

mixed

protected mixed mutateAttributeForArray(string $key, mixed $value)

Get the value of an attribute using its mutator for array conversion.

Parameters

string $key
mixed $value

Return Value

mixed

protected mixed castAttribute(string $key, mixed $value)

Cast an attribute to a native PHP type.

Parameters

string $key
mixed $value

Return Value

mixed

protected string getCastType(string $key)

Get the type of cast for a model attribute.

Parameters

string $key

Return Value

string

protected bool isCustomDateTimeCast(string $cast)

Determine if the cast type is a custom date time cast.

Parameters

string $cast

Return Value

bool

mixed setAttribute(string $key, mixed $value)

Set a given attribute on the model.

Parameters

string $key
mixed $value

Return Value

mixed

bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

Parameters

string $key

Return Value

bool

protected mixed setMutatedAttributeValue(string $key, mixed $value)

Set the value of an attribute using its mutator.

Parameters

string $key
mixed $value

Return Value

mixed

protected bool isDateAttribute(string $key)

Determine if the given attribute is a date or date castable.

Parameters

string $key

Return Value

bool

$this fillJsonAttribute(string $key, mixed $value)

Set a given JSON attribute on the model.

Parameters

string $key
mixed $value

Return Value

$this

protected $this getArrayAttributeWithValue(string $path, string $key, mixed $value)

Get an array attribute with the given key and value set.

Parameters

string $path
string $key
mixed $value

Return Value

$this

protected array getArrayAttributeByKey(string $key)

Get an array attribute or return an empty array if it is not set.

Parameters

string $key

Return Value

array

protected string castAttributeAsJson(string $key, mixed $value)

Cast the given attribute to JSON.

Parameters

string $key
mixed $value

Return Value

string

protected string asJson(mixed $value)

Encode the given value as JSON.

Parameters

mixed $value

Return Value

string

mixed fromJson(string $value, bool $asObject = false)

Decode the given JSON back into an array or object.

Parameters

string $value
bool $asObject

Return Value

mixed

protected Carbon asDate(mixed $value)

Return a timestamp as DateTime object with time set to 00:00:00.

Parameters

mixed $value

Return Value

Carbon

protected Carbon asDateTime(mixed $value)

Return a timestamp as DateTime object.

Parameters

mixed $value

Return Value

Carbon

protected bool isStandardDateFormat(string $value)

Determine if the given value is a standard date format.

Parameters

string $value

Return Value

bool

string fromDateTime(DateTime|int $value)

Convert a DateTime to a storable string.

Parameters

DateTime|int $value

Return Value

string

protected int asTimestamp(mixed $value)

Return a timestamp as unix timestamp.

Parameters

mixed $value

Return Value

int

protected string serializeDate(DateTimeInterface $date)

Prepare a date for array / JSON serialization.

Parameters

DateTimeInterface $date

Return Value

string

array getDates()

Get the attributes that should be converted to dates.

Return Value

array

string getDateFormat()

Get the format for database stored dates.

Return Value

string

$this setDateFormat(string $format)

Set the date format used by the model.

Parameters

string $format

Return Value

$this

bool hasCast(string $key, array|string|null $types = null)

Determine whether an attribute should be cast to a native type.

Parameters

string $key
array|string|null $types

Return Value

bool

array getCasts()

Get the casts array.

Return Value

array

protected bool isDateCastable(string $key)

Determine whether a value is Date / DateTime castable for inbound manipulation.

Parameters

string $key

Return Value

bool

protected bool isJsonCastable(string $key)

Determine whether a value is JSON castable for inbound manipulation.

Parameters

string $key

Return Value

bool

array getAttributes()

Get all of the current attributes on the model.

Return Value

array

$this setRawAttributes(array $attributes, bool $sync = false)

Set the array of model attributes. No checking is done.

Parameters

array $attributes
bool $sync

Return Value

$this

mixed|array getOriginal(string|null $key = null, mixed $default = null)

Get the model's original attribute values.

Parameters

string|null $key
mixed $default

Return Value

mixed|array

array only(array|mixed $attributes)

Get a subset of the model's attributes.

Parameters

array|mixed $attributes

Return Value

array

$this syncOriginal()

Sync the original attributes with the current.

Return Value

$this

$this syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

Parameters

string $attribute

Return Value

$this

$this syncChanges()

Sync the changed attributes.

Return Value

$this

bool isDirty(array|string|null $attributes = null)

Determine if the model or given attribute(s) have been modified.

Parameters

array|string|null $attributes

Return Value

bool

bool isClean(array|string|null $attributes = null)

Determine if the model or given attribute(s) have remained the same.

Parameters

array|string|null $attributes

Return Value

bool

bool wasChanged(array|string|null $attributes = null)

Determine if the model or given attribute(s) have been modified.

Parameters

array|string|null $attributes

Return Value

bool

protected bool hasChanges(array $changes, array|string|null $attributes = null)

Determine if the given attributes were changed.

Parameters

array $changes
array|string|null $attributes

Return Value

bool

array getDirty()

Get the attributes that have been changed since last sync.

Return Value

array

array getChanges()

Get the attributes that were changed.

Return Value

array

protected bool originalIsEquivalent(string $key, mixed $current)

Determine if the new and old values for a given key are equivalent.

Parameters

string $key
mixed $current

Return Value

bool

$this append(array|string $attributes)

Append attributes to query when building a query.

Parameters

array|string $attributes

Return Value

$this

$this setAppends(array $appends)

Set the accessors to append to model arrays.

Parameters

array $appends

Return Value

$this

array getMutatedAttributes()

Get the mutated attributes for a given instance.

Return Value

array

static void cacheMutatedAttributes(string $class)

Extract and cache all the mutated attributes of a class.

Parameters

string $class

Return Value

void

static protected array getMutatorMethods(mixed $class)

Get all of the attribute mutator methods.

Parameters

mixed $class

Return Value

array

static void observe(object|array|string $classes)

Register observers with the model.

Parameters

object|array|string $classes

Return Value

void

protected void registerObserver(object|string $class)

Register a single observer with the model.

Parameters

object|string $class

Return Value

void

array getObservableEvents()

Get the observable event names.

Return Value

array

$this setObservableEvents(array $observables)

Set the observable event names.

Parameters

array $observables

Return Value

$this

void addObservableEvents(array|mixed $observables)

Add an observable event name.

Parameters

array|mixed $observables

Return Value

void

void removeObservableEvents(array|mixed $observables)

Remove an observable event name.

Parameters

array|mixed $observables

Return Value

void

static protected void registerModelEvent(string $event, Closure|string $callback)

Register a model event with the dispatcher.

Parameters

string $event
Closure|string $callback

Return Value

void

protected mixed fireModelEvent(string $event, bool $halt = true)

Fire the given event for the model.

Parameters

string $event
bool $halt

Return Value

mixed

protected mixed|null fireCustomModelEvent(string $event, string $method)

Fire a custom model event for the given event.

Parameters

string $event
string $method

Return Value

mixed|null

protected mixed filterModelEventResults(mixed $result)

Filter the model event results.

Parameters

mixed $result

Return Value

mixed

static void retrieved(Closure|string $callback)

Register a retrieved model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

static void saving(Closure|string $callback)

Register a saving model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

static void saved(Closure|string $callback)

Register a saved model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

static void updating(Closure|string $callback)

Register an updating model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

static void updated(Closure|string $callback)

Register an updated model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

static void creating(Closure|string $callback)

Register a creating model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

static void created(Closure|string $callback)

Register a created model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

static void deleting(Closure|string $callback)

Register a deleting model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

static void deleted(Closure|string $callback)

Register a deleted model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

static void flushEventListeners()

Remove all of the event listeners for the model.

Return Value

void

static Dispatcher getEventDispatcher()

Get the event dispatcher instance.

Return Value

Dispatcher

static void setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

Parameters

Dispatcher $dispatcher

Return Value

void

static void unsetEventDispatcher()

Unset the event dispatcher for models.

Return Value

void

static mixed addGlobalScope(Scope|Closure|string $scope, Closure $implementation = null)

Register a new global scope on the model.

Parameters

Scope|Closure|string $scope
Closure $implementation

Return Value

mixed

Exceptions

InvalidArgumentException

static bool hasGlobalScope(Scope|string $scope)

Determine if a model has a global scope.

Parameters

Scope|string $scope

Return Value

bool

static Scope|Closure|null getGlobalScope(Scope|string $scope)

Get a global scope registered with the model.

Parameters

Scope|string $scope

Return Value

Scope|Closure|null

array getGlobalScopes()

Get the global scopes for this class instance.

Return Value

array

HasOne hasOne(string $related, string $foreignKey = null, string $localKey = null)

Define a one-to-one relationship.

Parameters

string $related
string $foreignKey
string $localKey

Return Value

HasOne

protected HasOne newHasOne(Builder $query, Model $parent, string $foreignKey, string $localKey)

Instantiate a new HasOne relationship.

Parameters

Builder $query
Model $parent
string $foreignKey
string $localKey

Return Value

HasOne

MorphOne morphOne(string $related, string $name, string $type = null, string $id = null, string $localKey = null)

Define a polymorphic one-to-one relationship.

Parameters

string $related
string $name
string $type
string $id
string $localKey

Return Value

MorphOne

protected MorphOne newMorphOne(Builder $query, Model $parent, string $type, string $id, string $localKey)

Instantiate a new MorphOne relationship.

Parameters

Builder $query
Model $parent
string $type
string $id
string $localKey

Return Value

MorphOne

BelongsTo belongsTo(string $related, string $foreignKey = null, string $ownerKey = null, string $relation = null)

Define an inverse one-to-one or many relationship.

Parameters

string $related
string $foreignKey
string $ownerKey
string $relation

Return Value

BelongsTo

protected BelongsTo newBelongsTo(Builder $query, Model $child, string $foreignKey, string $ownerKey, string $relation)

Instantiate a new BelongsTo relationship.

Parameters

Builder $query
Model $child
string $foreignKey
string $ownerKey
string $relation

Return Value

BelongsTo

MorphTo morphTo(string $name = null, string $type = null, string $id = null, string $ownerKey = null)

Define a polymorphic, inverse one-to-one or many relationship.

Parameters

string $name
string $type
string $id
string $ownerKey

Return Value

MorphTo

protected MorphTo morphEagerTo(string $name, string $type, string $id, string $ownerKey)

Define a polymorphic, inverse one-to-one or many relationship.

Parameters

string $name
string $type
string $id
string $ownerKey

Return Value

MorphTo

protected MorphTo morphInstanceTo(string $target, string $name, string $type, string $id, string $ownerKey)

Define a polymorphic, inverse one-to-one or many relationship.

Parameters

string $target
string $name
string $type
string $id
string $ownerKey

Return Value

MorphTo

protected MorphTo newMorphTo(Builder $query, Model $parent, string $foreignKey, string $ownerKey, string $type, string $relation)

Instantiate a new MorphTo relationship.

Parameters

Builder $query
Model $parent
string $foreignKey
string $ownerKey
string $type
string $relation

Return Value

MorphTo

static string getActualClassNameForMorph(string $class)

Retrieve the actual class name for a given morph class.

Parameters

string $class

Return Value

string

protected string guessBelongsToRelation()

Guess the "belongs to" relationship name.

Return Value

string

HasMany hasMany(string $related, string $foreignKey = null, string $localKey = null)

Define a one-to-many relationship.

Parameters

string $related
string $foreignKey
string $localKey

Return Value

HasMany

protected HasMany newHasMany(Builder $query, Model $parent, string $foreignKey, string $localKey)

Instantiate a new HasMany relationship.

Parameters

Builder $query
Model $parent
string $foreignKey
string $localKey

Return Value

HasMany

HasManyThrough hasManyThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null, string|null $localKey = null, string|null $secondLocalKey = null)

Define a has-many-through relationship.

Parameters

string $related
string $through
string|null $firstKey
string|null $secondKey
string|null $localKey
string|null $secondLocalKey

Return Value

HasManyThrough

protected HasManyThrough newHasManyThrough(Builder $query, Model $farParent, Model $throughParent, string $firstKey, string $secondKey, string $localKey, string $secondLocalKey)

Instantiate a new HasManyThrough relationship.

Parameters

Builder $query
Model $farParent
Model $throughParent
string $firstKey
string $secondKey
string $localKey
string $secondLocalKey

Return Value

HasManyThrough

MorphMany morphMany(string $related, string $name, string $type = null, string $id = null, string $localKey = null)

Define a polymorphic one-to-many relationship.

Parameters

string $related
string $name
string $type
string $id
string $localKey

Return Value

MorphMany

protected MorphMany newMorphMany(Builder $query, Model $parent, string $type, string $id, string $localKey)

Instantiate a new MorphMany relationship.

Parameters

Builder $query
Model $parent
string $type
string $id
string $localKey

Return Value

MorphMany

BelongsToMany belongsToMany(string $related, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null, string $relation = null)

Define a many-to-many relationship.

Parameters

string $related
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey
string $relation

Return Value

BelongsToMany

protected BelongsToMany newBelongsToMany(Builder $query, Model $parent, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string $relationName = null)

Instantiate a new BelongsToMany relationship.

Parameters

Builder $query
Model $parent
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey
string $relationName

Return Value

BelongsToMany

MorphToMany morphToMany(string $related, string $name, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null, bool $inverse = false)

Define a polymorphic many-to-many relationship.

Parameters

string $related
string $name
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey
bool $inverse

Return Value

MorphToMany

protected MorphToMany newMorphToMany(Builder $query, Model $parent, string $name, string $table, string $foreignPivotKey, string $relatedPivotKey, string $parentKey, string $relatedKey, string $relationName = null, bool $inverse = false)

Instantiate a new MorphToMany relationship.

Parameters

Builder $query
Model $parent
string $name
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey
string $relationName
bool $inverse

Return Value

MorphToMany

MorphToMany morphedByMany(string $related, string $name, string $table = null, string $foreignPivotKey = null, string $relatedPivotKey = null, string $parentKey = null, string $relatedKey = null)

Define a polymorphic, inverse many-to-many relationship.

Parameters

string $related
string $name
string $table
string $foreignPivotKey
string $relatedPivotKey
string $parentKey
string $relatedKey

Return Value

MorphToMany

protected string guessBelongsToManyRelation()

Get the relationship name of the belongs to many.

Return Value

string

string joiningTable(string $related)

Get the joining table name for a many-to-many relation.

Parameters

string $related

Return Value

string

bool touches(string $relation)

Determine if the model touches a given relation.

Parameters

string $relation

Return Value

bool

void touchOwners()

Touch the owning relations of the model.

Return Value

void

protected array getMorphs(string $name, string $type, string $id)

Get the polymorphic relationship columns.

Parameters

string $name
string $type
string $id

Return Value

array

string getMorphClass()

Get the class name for polymorphic relations.

Return Value

string

protected mixed newRelatedInstance(string $class)

Create a new model instance for a related model.

Parameters

string $class

Return Value

mixed

array getRelations()

Get all the loaded relations for the instance.

Return Value

array

mixed getRelation(string $relation)

Get a specified relationship.

Parameters

string $relation

Return Value

mixed

bool relationLoaded(string $key)

Determine if the given relation is loaded.

Parameters

string $key

Return Value

bool

$this setRelation(string $relation, mixed $value)

Set the given relationship on the model.

Parameters

string $relation
mixed $value

Return Value

$this

$this unsetRelation(string $relation)

Unset a loaded relationship.

Parameters

string $relation

Return Value

$this

$this setRelations(array $relations)

Set the entire relations array on the model.

Parameters

array $relations

Return Value

$this

array getTouchedRelations()

Get the relationships that are touched on save.

Return Value

array

$this setTouchedRelations(array $touches)

Set the relationships that are touched on save.

Parameters

array $touches

Return Value

$this

bool touch()

Update the model's update timestamp.

Return Value

bool

protected void updateTimestamps()

Update the creation and update timestamps.

Return Value

void

$this setCreatedAt(mixed $value)

Set the value of the "created at" attribute.

Parameters

mixed $value

Return Value

$this

$this setUpdatedAt(mixed $value)

Set the value of the "updated at" attribute.

Parameters

mixed $value

Return Value

$this

Carbon freshTimestamp()

Get a fresh timestamp for the model.

Return Value

Carbon

string freshTimestampString()

Get a fresh timestamp for the model.

Return Value

string

bool usesTimestamps()

Determine if the model uses timestamps.

Return Value

bool

string getCreatedAtColumn()

Get the name of the "created at" column.

Return Value

string

string getUpdatedAtColumn()

Get the name of the "updated at" column.

Return Value

string

array getHidden()

Get the hidden attributes for the model.

Return Value

array

$this setHidden(array $hidden)

Set the hidden attributes for the model.

Parameters

array $hidden

Return Value

$this

void addHidden(array|string|null $attributes = null)

Add hidden attributes for the model.

Parameters

array|string|null $attributes

Return Value

void

array getVisible()

Get the visible attributes for the model.

Return Value

array

$this setVisible(array $visible)

Set the visible attributes for the model.

Parameters

array $visible

Return Value

$this

void addVisible(array|string|null $attributes = null)

Add visible attributes for the model.

Parameters

array|string|null $attributes

Return Value

void

$this makeVisible(array|string $attributes)

Make the given, typically hidden, attributes visible.

Parameters

array|string $attributes

Return Value

$this

$this makeHidden(array|string $attributes)

Make the given, typically visible, attributes hidden.

Parameters

array|string $attributes

Return Value

$this

array getFillable()

Get the fillable attributes for the model.

Return Value

array

$this fillable(array $fillable)

Set the fillable attributes for the model.

Parameters

array $fillable

Return Value

$this

array getGuarded()

Get the guarded attributes for the model.

Return Value

array

$this guard(array $guarded)

Set the guarded attributes for the model.

Parameters

array $guarded

Return Value

$this

static void unguard(bool $state = true)

Disable all mass assignable restrictions.

Parameters

bool $state

Return Value

void

static void reguard()

Enable the mass assignment restrictions.

Return Value

void

static bool isUnguarded()

Determine if current state is "unguarded".

Return Value

bool

static mixed unguarded(callable $callback)

Run the given callable while being unguarded.

Parameters

callable $callback

Return Value

mixed

bool isFillable(string $key)

Determine if the given attribute may be mass assigned.

Parameters

string $key

Return Value

bool

bool isGuarded(string $key)

Determine if the given key is guarded.

Parameters

string $key

Return Value

bool

bool totallyGuarded()

Determine if the model is totally guarded.

Return Value

bool

protected array fillableFromArray(array $attributes)

Get the fillable attributes of a given array.

Parameters

array $attributes

Return Value

array

void __construct(array $attributes = [])

Create a new Eloquent model instance.

Parameters

array $attributes

Return Value

void

protected void bootIfNotBooted()

Check if the model needs to be booted and if so, do it.

Return Value

void

static protected void boot()

The "booting" method of the model.

Return Value

void

static protected void bootTraits()

Boot all of the bootable traits on the model.

Return Value

void

static void clearBootedModels()

Clear the list of booted models so they will be re-booted.

Return Value

void

static void withoutTouching(callable $callback)

Disables relationship model touching for the current class during given callback scope.

Parameters

callable $callback

Return Value

void

static void withoutTouchingOn(array $models, callable $callback)

Disables relationship model touching for the given model classes during given callback scope.

Parameters

array $models
callable $callback

Return Value

void

static bool isIgnoringTouch(string|null $class = null)

Determine if the given model is ignoring touches.

Parameters

string|null $class

Return Value

bool

$this fill(array $attributes)

Fill the model with an array of attributes.

Parameters

array $attributes

Return Value

$this

Exceptions

MassAssignmentException

$this forceFill(array $attributes)

Fill the model with an array of attributes. Force mass assignment.

Parameters

array $attributes

Return Value

$this

string qualifyColumn(string $column)

Qualify the given column name by the model's table.

Parameters

string $column

Return Value

string

protected string removeTableFromKey(string $key)

Remove the table name from a given key.

Parameters

string $key

Return Value

string

Model newInstance(array $attributes = [], bool $exists = false)

Create a new instance of the given model.

Parameters

array $attributes
bool $exists

Return Value

Model

Model newFromBuilder(array $attributes = [], string|null $connection = null)

Create a new model instance that is existing.

Parameters

array $attributes
string|null $connection

Return Value

Model

static Builder on(string|null $connection = null)

Begin querying the model on a given connection.

Parameters

string|null $connection

Return Value

Builder

static Builder onWriteConnection()

Begin querying the model on the write connection.

Return Value

Builder

static Collection|Model[] all(array|mixed $columns = ['*'])

Get all of the models from the database.

Parameters

array|mixed $columns

Return Value

Collection|Model[]

static Builder|Model with(array|string $relations)

Begin querying a model with eager loading.

Parameters

array|string $relations

Return Value

Builder|Model

$this load(array|string $relations)

Eager load relations on the model.

Parameters

array|string $relations

Return Value

$this

$this loadMissing(array|string $relations)

Eager load relations on the model if they are not already eager loaded.

Parameters

array|string $relations

Return Value

$this

protected int increment(string $column, float|int $amount = 1, array $extra = [])

Increment a column's value by a given amount.

Parameters

string $column
float|int $amount
array $extra

Return Value

int

protected int decrement(string $column, float|int $amount = 1, array $extra = [])

Decrement a column's value by a given amount.

Parameters

string $column
float|int $amount
array $extra

Return Value

int

protected int incrementOrDecrement(string $column, float|int $amount, array $extra, string $method)

Run the increment or decrement method on the model.

Parameters

string $column
float|int $amount
array $extra
string $method

Return Value

int

protected void incrementOrDecrementAttributeValue(string $column, float|int $amount, array $extra, string $method)

Increment the underlying attribute value and sync with original.

Parameters

string $column
float|int $amount
array $extra
string $method

Return Value

void

bool update(array $attributes = [], array $options = [])

Update the model in the database.

Parameters

array $attributes
array $options

Return Value

bool

bool push()

Save the model and all of its relationships.

Return Value

bool

bool save(array $options = [])

Save the model to the database.

Parameters

array $options

Return Value

bool

bool saveOrFail(array $options = [])

Save the model to the database using transaction.

Parameters

array $options

Return Value

bool

Exceptions

Throwable

protected void finishSave(array $options)

Perform any actions that are necessary after the model is saved.

Parameters

array $options

Return Value

void

protected bool performUpdate(Builder $query)

Perform a model update operation.

Parameters

Builder $query

Return Value

bool

protected Builder setKeysForSaveQuery(Builder $query)

Set the keys for a save update query.

Parameters

Builder $query

Return Value

Builder

protected mixed getKeyForSaveQuery()

Get the primary key value for a save query.

Return Value

mixed

protected bool performInsert(Builder $query)

Perform a model insert operation.

Parameters

Builder $query

Return Value

bool

protected void insertAndSetId(Builder $query, array $attributes)

Insert the given attributes and set the ID on the model.

Parameters

Builder $query
array $attributes

Return Value

void

static int destroy(array|int $ids)

Destroy the models for the given IDs.

Parameters

array|int $ids

Return Value

int

bool|null delete()

Delete the model from the database.

Return Value

bool|null

Exceptions

Exception

bool|null forceDelete()

Force a hard delete on a soft deleted model.

This method protects developers from running forceDelete when trait is missing.

Return Value

bool|null

protected void performDeleteOnModel()

Perform the actual delete query on this model instance.

Return Value

void

static Builder query()

Begin querying the model.

Return Value

Builder

Builder newQuery()

Get a new query builder for the model's table.

Return Value

Builder

Builder|Model newModelQuery()

Get a new query builder that doesn't have any global scopes or eager loading.

Return Value

Builder|Model

Builder newQueryWithoutRelationships()

Get a new query builder with no relationships loaded.

Return Value

Builder

Builder registerGlobalScopes(Builder $builder)

Register the global scopes for this builder instance.

Parameters

Builder $builder

Return Value

Builder

Builder|Model newQueryWithoutScopes()

Get a new query builder that doesn't have any global scopes.

Return Value

Builder|Model

Builder newQueryWithoutScope(Scope|string $scope)

Get a new query instance without a given scope.

Parameters

Scope|string $scope

Return Value

Builder

Builder newQueryForRestoration(array|int $ids)

Get a new query to restore one or more models by their queueable IDs.

Parameters

array|int $ids

Return Value

Builder

Builder|Model newEloquentBuilder(Builder $query)

Create a new Eloquent query builder for the model.

Parameters

Builder $query

Return Value

Builder|Model

protected Builder newBaseQueryBuilder()

Get a new query builder instance for the connection.

Return Value

Builder

Collection newCollection(array $models = [])

Create a new Eloquent Collection instance.

Parameters

array $models

Return Value

Collection

Pivot newPivot(Model $parent, array $attributes, string $table, bool $exists, string|null $using = null)

Create a new pivot model instance.

Parameters

Model $parent
array $attributes
string $table
bool $exists
string|null $using

Return Value

Pivot

array toArray()

Convert the model instance to an array.

Return Value

array

string toJson(int $options)

Convert the model instance to JSON.

Parameters

int $options

Return Value

string

Exceptions

JsonEncodingException

array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

Model|null fresh(array|string $with = [])

Reload a fresh model instance from the database.

Parameters

array|string $with

Return Value

Model|null

$this refresh()

Reload the current model instance with fresh attributes from the database.

Return Value

$this

Model replicate(array $except = null)

Clone the model into a new, non-existing instance.

Parameters

array $except

Return Value

Model

bool is(Model|null $model)

Determine if two models have the same ID and belong to the same table.

Parameters

Model|null $model

Return Value

bool

bool isNot(Model|null $model)

Determine if two models are not the same.

Parameters

Model|null $model

Return Value

bool

Connection getConnection()

Get the database connection for the model.

Return Value

Connection

string getConnectionName()

Get the current connection name for the model.

Return Value

string

$this setConnection(string $name)

Set the connection associated with the model.

Parameters

string $name

Return Value

$this

static Connection resolveConnection(string|null $connection = null)

Resolve a connection instance.

Parameters

string|null $connection

Return Value

Connection

static ConnectionResolverInterface getConnectionResolver()

Get the connection resolver instance.

static void setConnectionResolver(ConnectionResolverInterface $resolver)

Set the connection resolver instance.

Parameters

ConnectionResolverInterface $resolver

Return Value

void

static void unsetConnectionResolver()

Unset the connection resolver for models.

Return Value

void

string getTable()

Get the table associated with the model.

Return Value

string

$this setTable(string $table)

Set the table associated with the model.

Parameters

string $table

Return Value

$this

string getKeyName()

Get the primary key for the model.

Return Value

string

$this setKeyName(string $key)

Set the primary key for the model.

Parameters

string $key

Return Value

$this

string getQualifiedKeyName()

Get the table qualified key name.

Return Value

string

string getKeyType()

Get the auto-incrementing key type.

Return Value

string

$this setKeyType(string $type)

Set the data type for the primary key.

Parameters

string $type

Return Value

$this

bool getIncrementing()

Get the value indicating whether the IDs are incrementing.

Return Value

bool

$this setIncrementing(bool $value)

Set whether IDs are incrementing.

Parameters

bool $value

Return Value

$this

mixed getKey()

Get the value of the model's primary key.

Return Value

mixed

mixed getQueueableId()

Get the queueable identity for the entity.

Return Value

mixed

array getQueueableRelations()

Get the queueable relationships for the entity.

Return Value

array

string|null getQueueableConnection()

Get the queueable connection for the entity.

Return Value

string|null

mixed getRouteKey()

Get the value of the model's route key.

Return Value

mixed

string getRouteKeyName()

Get the route key for the model.

Return Value

string

Model|null resolveRouteBinding(mixed $value)

Retrieve the model for a bound value.

Parameters

mixed $value

Return Value

Model|null

string getForeignKey()

Get the default foreign key name for the model.

Return Value

string

int getPerPage()

Get the number of models to return per page.

Return Value

int

$this setPerPage(int $perPage)

Set the number of models to return per page.

Parameters

int $perPage

Return Value

$this

mixed __get(string $key)

Dynamically retrieve attributes on the model.

Parameters

string $key

Return Value

mixed

void __set(string $key, mixed $value)

Dynamically set attributes on the model.

Parameters

string $key
mixed $value

Return Value

void

bool offsetExists(mixed $offset)

Determine if the given attribute exists.

Parameters

mixed $offset

Return Value

bool

mixed offsetGet(mixed $offset)

Get the value for a given offset.

Parameters

mixed $offset

Return Value

mixed

void offsetSet(mixed $offset, mixed $value)

Set the value for a given offset.

Parameters

mixed $offset
mixed $value

Return Value

void

void offsetUnset(mixed $offset)

Unset the value for a given offset.

Parameters

mixed $offset

Return Value

void

bool __isset(string $key)

Determine if an attribute or relation exists on the model.

Parameters

string $key

Return Value

bool

void __unset(string $key)

Unset an attribute on the model.

Parameters

string $key

Return Value

void

mixed __call(string $method, array $parameters)

Handle dynamic method calls into the model.

Parameters

string $method
array $parameters

Return Value

mixed

static mixed __callStatic(string $method, array $parameters)

Handle dynamic static method calls into the method.

Parameters

string $method
array $parameters

Return Value

mixed

string __toString()

Convert the model to its string representation.

Return Value

string

void __wakeup()

When a model is being unserialized, check if it needs to be booted.

Return Value

void