Model
abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable mixin Builder mixin Builder
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 | $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 | $events | 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 |
$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. |
Methods
Add the date attributes to the attributes array.
Add the mutated attributes to the attributes array.
Add the casted attributes to the attributes array.
Get an attribute array of all arrayable attributes.
Get an attribute array of all arrayable values.
Get an attribute from the $attributes array.
Get a relationship value from a method.
Determine if a get mutator exists for an attribute.
Get the value of an attribute using its mutator.
Get the value of an attribute using its mutator for array conversion.
Cast an attribute to a native PHP type.
Set a given attribute on the model.
Determine if a set mutator exists for an attribute.
Determine if the given attribute is a date or date castable.
Set a given JSON attribute on the model.
Get an array attribute with the given key and value set.
Get an array attribute or return an empty array if it is not set.
Cast the given attribute to JSON.
Decode the given JSON back into an array or object.
Return a timestamp as DateTime object with time set to 00:00:00.
Determine if the given value is a standard date format.
Determine whether an attribute should be cast to a native type.
Determine whether a value is Date / DateTime castable for inbound manipulation.
Determine whether a value is JSON castable for inbound manipulation.
Set the array of model attributes. No checking is done.
Get the model's original attribute values.
Sync a single original attribute with its current value.
Determine if the model or given attribute(s) have been modified.
Determine if the model or given attribute(s) have remained the same.
Determine if the new and old values for a given key are numerically equivalent.
Append attributes to query when building a query.
Extract and cache all the mutated attributes of a class.
Get all of the attribute mutator methods.
Remove an observable event name.
Register a model event with the dispatcher.
Fire the given event for the model.
Fire a custom model event for the given event.
Register a new global scope on the model.
Define a one-to-one relationship.
Define a polymorphic one-to-one relationship.
Define an inverse one-to-one or many relationship.
Define a polymorphic, inverse one-to-one or many relationship.
Define a polymorphic, inverse one-to-one or many relationship.
Define a polymorphic, inverse one-to-one or many relationship.
Retrieve the actual class name for a given morph class.
Define a one-to-many relationship.
Define a has-many-through relationship.
Define a polymorphic one-to-many relationship.
Define a many-to-many relationship.
Define a polymorphic many-to-many relationship.
Define a polymorphic, inverse many-to-many relationship.
Get the relationship name of the belongs to many.
Get the joining table name for a many-to-many relation.
Determine if the model touches a given relation.
Get the polymorphic relationship columns.
Create a new model instance for a related model.
Set the specific relationship in the model.
Set the entire relations array on the model.
Set the relationships that are touched on save.
Add hidden attributes for the model.
Add visible attributes for the model.
Make the given, typically hidden, attributes visible.
Make the given, typically visible, attributes hidden.
Disable all mass assignable restrictions.
Run the given callable while being unguarded.
Determine if the given attribute may be mass assigned.
Get the fillable attributes of a given array.
Create a new Eloquent model instance.
Check if the model needs to be booted and if so, do it.
The "booting" method of the model.
Boot all of the bootable traits on the model.
Clear the list of booted models so they will be re-booted.
Fill the model with an array of attributes.
Fill the model with an array of attributes. Force mass assignment.
Remove the table name from a given key.
Create a new instance of the given model.
Create a new model instance that is existing.
Begin querying the model on the write connection.
Get all of the models from the database.
Eager load relations on the model.
Increment a column's value by a given amount.
Decrement a column's value by a given amount.
Run the increment or decrement method on the model.
Increment the underlying attribute value and sync with original.
Update the model in the database.
Save the model and all of its relationships.
Save the model to the database.
Save the model to the database using transaction.
Perform any actions that are necessary after the model is saved.
Get the primary key value for a save query.
Insert the given attributes and set the ID on the model.
Destroy the models for the given IDs.
Delete the model from the database.
Force a hard delete on a soft deleted model.
Perform the actual delete query on this model instance.
Get a new query builder that doesn't have any global scopes.
Get a new query builder instance for the connection.
Create a new Eloquent Collection instance.
Convert the model instance to an array.
Convert the model instance to JSON.
Convert the object into something JSON serializable.
Reload the current model instance with fresh attributes from the database.
Get the database connection for the model.
Get the current connection name for the model.
Set the connection associated with the model.
Resolve a connection instance.
Get the connection resolver instance.
Unset the connection resolver for models.
Get the table associated with the model.
Set the table associated with the model.
Get the primary key for the model.
Set the primary key for the model.
Get the table qualified key name.
Get the auto-incrementing key type.
Set the data type for the primary key.
Get the value indicating whether the IDs are incrementing.
Set whether IDs are incrementing.
Get the value of the model's primary key.
Get the queueable identity for the entity.
Get the value of the model's route key.
Get the route key for the model.
Get the default foreign key name for the model.
Get the number of models to return per page.
Set the number of models to return per page.
Dynamically retrieve attributes on the model.
Dynamically set attributes on the model.
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 or relation exists on the model.
Unset an attribute on the model.
Handle dynamic method calls into the model.
Handle dynamic static method calls into the method.
Convert the model to its string representation.
When a model is being unserialized, check if it needs to be booted.
Details
in
HasAttributes at line 78
array
attributesToArray()
Convert the model's attributes to an array.
in
HasAttributes at line 114
protected array
addDateAttributesToArray(array $attributes)
Add the date attributes to the attributes array.
in
HasAttributes at line 136
protected array
addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)
Add the mutated attributes to the attributes array.
in
HasAttributes at line 164
protected array
addCastAttributesToArray(array $attributes, array $mutatedAttributes)
Add the casted attributes to the attributes array.
in
HasAttributes at line 195
protected array
getArrayableAttributes()
Get an attribute array of all arrayable attributes.
in
HasAttributes at line 205
protected array
getArrayableAppends()
Get all of the appendable values that are arrayable.
in
HasAttributes at line 221
array
relationsToArray()
Get the model's relationships in array form.
in
HasAttributes at line 265
protected array
getArrayableRelations()
Get an attribute array of all arrayable relations.
in
HasAttributes at line 276
protected array
getArrayableItems(array $values)
Get an attribute array of all arrayable values.
in
HasAttributes at line 295
mixed
getAttribute(string $key)
Get an attribute from the model.
in
HasAttributes at line 325
mixed
getAttributeValue(string $key)
Get a plain attribute (not a relationship).
in
HasAttributes at line 360
protected mixed
getAttributeFromArray(string $key)
Get an attribute from the $attributes array.
in
HasAttributes at line 373
mixed
getRelationValue(string $key)
Get a relationship.
in
HasAttributes at line 398
protected mixed
getRelationshipFromMethod(string $method)
Get a relationship value from a method.
in
HasAttributes at line 418
bool
hasGetMutator(string $key)
Determine if a get mutator exists for an attribute.
in
HasAttributes at line 430
protected mixed
mutateAttribute(string $key, mixed $value)
Get the value of an attribute using its mutator.
in
HasAttributes at line 442
protected mixed
mutateAttributeForArray(string $key, mixed $value)
Get the value of an attribute using its mutator for array conversion.
in
HasAttributes at line 456
protected mixed
castAttribute(string $key, mixed $value)
Cast an attribute to a native PHP type.
in
HasAttributes at line 499
protected string
getCastType(string $key)
Get the type of cast for a model attribute.
in
HasAttributes at line 511
$this
setAttribute(string $key, mixed $value)
Set a given attribute on the model.
in
HasAttributes at line 551
bool
hasSetMutator(string $key)
Determine if a set mutator exists for an attribute.
in
HasAttributes at line 562
protected bool
isDateAttribute(string $key)
Determine if the given attribute is a date or date castable.
in
HasAttributes at line 575
$this
fillJsonAttribute(string $key, mixed $value)
Set a given JSON attribute on the model.
in
HasAttributes at line 594
protected $this
getArrayAttributeWithValue(string $path, string $key, mixed $value)
Get an array attribute with the given key and value set.
in
HasAttributes at line 607
protected array
getArrayAttributeByKey(string $key)
Get an array attribute or return an empty array if it is not set.
in
HasAttributes at line 620
protected string
castAttributeAsJson(string $key, mixed $value)
Cast the given attribute to JSON.
in
HasAttributes at line 639
protected string
asJson(mixed $value)
Encode the given value as JSON.
in
HasAttributes at line 651
mixed
fromJson(string $value, bool $asObject = false)
Decode the given JSON back into an array or object.
in
HasAttributes at line 662
protected Carbon
asDate(mixed $value)
Return a timestamp as DateTime object with time set to 00:00:00.
in
HasAttributes at line 673
protected Carbon
asDateTime(mixed $value)
Return a timestamp as DateTime object.
in
HasAttributes at line 719
protected bool
isStandardDateFormat(string $value)
Determine if the given value is a standard date format.
in
HasAttributes at line 730
string
fromDateTime(DateTime|int $value)
Convert a DateTime to a storable string.
in
HasAttributes at line 743
protected int
asTimestamp(mixed $value)
Return a timestamp as unix timestamp.
in
HasAttributes at line 754
protected string
serializeDate(DateTimeInterface $date)
Prepare a date for array / JSON serialization.
in
HasAttributes at line 764
array
getDates()
Get the attributes that should be converted to dates.
in
HasAttributes at line 778
protected string
getDateFormat()
Get the format for database stored dates.
in
HasAttributes at line 789
$this
setDateFormat(string $format)
Set the date format used by the model.
in
HasAttributes at line 803
bool
hasCast(string $key, array|string|null $types = null)
Determine whether an attribute should be cast to a native type.
in
HasAttributes at line 817
array
getCasts()
Get the casts array.
in
HasAttributes at line 832
protected bool
isDateCastable(string $key)
Determine whether a value is Date / DateTime castable for inbound manipulation.
in
HasAttributes at line 843
protected bool
isJsonCastable(string $key)
Determine whether a value is JSON castable for inbound manipulation.
in
HasAttributes at line 853
array
getAttributes()
Get all of the current attributes on the model.
in
HasAttributes at line 865
$this
setRawAttributes(array $attributes, bool $sync = false)
Set the array of model attributes. No checking is done.
in
HasAttributes at line 883
mixed|array
getOriginal(string|null $key = null, mixed $default = null)
Get the model's original attribute values.
in
HasAttributes at line 893
$this
syncOriginal()
Sync the original attributes with the current.
in
HasAttributes at line 906
$this
syncOriginalAttribute(string $attribute)
Sync a single original attribute with its current value.
in
HasAttributes at line 919
bool
isDirty(array|string|null $attributes = null)
Determine if the model or given attribute(s) have been modified.
in
HasAttributes at line 951
bool
isClean(array|string|null $attributes = null)
Determine if the model or given attribute(s) have remained the same.
in
HasAttributes at line 961
array
getDirty()
Get the attributes that have been changed since last sync.
in
HasAttributes at line 983
protected bool
originalIsNumericallyEquivalent(string $key)
Determine if the new and old values for a given key are numerically equivalent.
in
HasAttributes at line 1002
$this
append(array|string $attributes)
Append attributes to query when building a query.
in
HasAttributes at line 1017
$this
setAppends(array $appends)
Set the accessors to append to model arrays.
in
HasAttributes at line 1029
array
getMutatedAttributes()
Get the mutated attributes for a given instance.
in
HasAttributes at line 1046
static void
cacheMutatedAttributes(string $class)
Extract and cache all the mutated attributes of a class.
in
HasAttributes at line 1059
static protected array
getMutatorMethods(mixed $class)
Get all of the attribute mutator methods.
in
HasEvents at line 33
static void
observe(object|string $class)
Register an observer with the Model.
in
HasEvents at line 54
array
getObservableEvents()
Get the observable event names.
in
HasEvents at line 72
$this
setObservableEvents(array $observables)
Set the observable event names.
in
HasEvents at line 85
void
addObservableEvents(array|mixed $observables)
Add an observable event name.
in
HasEvents at line 98
void
removeObservableEvents(array|mixed $observables)
Remove an observable event name.
in
HasEvents at line 112
static protected void
registerModelEvent(string $event, Closure|string $callback)
Register a model event with the dispatcher.
in
HasEvents at line 128
protected mixed
fireModelEvent(string $event, bool $halt = true)
Fire the given event for the model.
in
HasEvents at line 159
protected mixed|null
fireCustomModelEvent(string $event, string $method)
Fire a custom model event for the given event.
in
HasEvents at line 178
protected mixed
filterModelEventResults(mixed $result)
Filter the model event results.
in
HasEvents at line 195
static void
saving(Closure|string $callback)
Register a saving model event with the dispatcher.
in
HasEvents at line 206
static void
saved(Closure|string $callback)
Register a saved model event with the dispatcher.
in
HasEvents at line 217
static void
updating(Closure|string $callback)
Register an updating model event with the dispatcher.
in
HasEvents at line 228
static void
updated(Closure|string $callback)
Register an updated model event with the dispatcher.
in
HasEvents at line 239
static void
creating(Closure|string $callback)
Register a creating model event with the dispatcher.
in
HasEvents at line 250
static void
created(Closure|string $callback)
Register a created model event with the dispatcher.
in
HasEvents at line 261
static void
deleting(Closure|string $callback)
Register a deleting model event with the dispatcher.
in
HasEvents at line 272
static void
deleted(Closure|string $callback)
Register a deleted model event with the dispatcher.
in
HasEvents at line 282
static void
flushEventListeners()
Remove all of the event listeners for the model.
in
HasEvents at line 300
static Dispatcher
getEventDispatcher()
Get the event dispatcher instance.
in
HasEvents at line 311
static void
setEventDispatcher(Dispatcher $dispatcher)
Set the event dispatcher instance.
in
HasEvents at line 321
static void
unsetEventDispatcher()
Unset the event dispatcher for models.
in
HasGlobalScopes at line 21
static mixed
addGlobalScope(Scope|Closure|string $scope, Closure $implementation = null)
Register a new global scope on the model.
in
HasGlobalScopes at line 40
static bool
hasGlobalScope(Scope|string $scope)
Determine if a model has a global scope.
in
HasGlobalScopes at line 51
static Scope|Closure|null
getGlobalScope(Scope|string $scope)
Get a global scope registered with the model.
in
HasGlobalScopes at line 67
array
getGlobalScopes()
Get the global scopes for this class instance.
in
HasRelationships at line 54
HasOne
hasOne(string $related, string $foreignKey = null, string $localKey = null)
Define a one-to-one relationship.
in
HasRelationships at line 75
MorphOne
morphOne(string $related, string $name, string $type = null, string $id = null, string $localKey = null)
Define a polymorphic one-to-one relationship.
in
HasRelationships at line 97
BelongsTo
belongsTo(string $related, string $foreignKey = null, string $ownerKey = null, string $relation = null)
Define an inverse one-to-one or many relationship.
in
HasRelationships at line 133
MorphTo
morphTo(string $name = null, string $type = null, string $id = null)
Define a polymorphic, inverse one-to-one or many relationship.
in
HasRelationships at line 160
protected MorphTo
morphEagerTo(string $name, string $type, string $id)
Define a polymorphic, inverse one-to-one or many relationship.
in
HasRelationships at line 176
protected MorphTo
morphInstanceTo(string $target, string $name, string $type, string $id)
Define a polymorphic, inverse one-to-one or many relationship.
in
HasRelationships at line 193
static string
getActualClassNameForMorph(string $class)
Retrieve the actual class name for a given morph class.
in
HasRelationships at line 203
protected string
guessBelongsToRelation()
Guess the "belongs to" relationship name.
in
HasRelationships at line 218
HasMany
hasMany(string $related, string $foreignKey = null, string $localKey = null)
Define a one-to-many relationship.
in
HasRelationships at line 241
HasManyThrough
hasManyThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null, string|null $localKey = null)
Define a has-many-through relationship.
in
HasRelationships at line 266
MorphMany
morphMany(string $related, string $name, string $type = null, string $id = null, string $localKey = null)
Define a polymorphic one-to-many relationship.
in
HasRelationships at line 292
BelongsToMany
belongsToMany(string $related, string $table = null, string $foreignKey = null, string $relatedKey = null, string $relation = null)
Define a many-to-many relationship.
in
HasRelationships at line 333
MorphToMany
morphToMany(string $related, string $name, string $table = null, string $foreignKey = null, string $relatedKey = null, bool $inverse = false)
Define a polymorphic many-to-many relationship.
in
HasRelationships at line 367
MorphToMany
morphedByMany(string $related, string $name, string $table = null, string $foreignKey = null, string $relatedKey = null)
Define a polymorphic, inverse many-to-many relationship.
in
HasRelationships at line 384
protected string
guessBelongsToManyRelation()
Get the relationship name of the belongs to many.
in
HasRelationships at line 399
string
joiningTable(string $related)
Get the joining table name for a many-to-many relation.
in
HasRelationships at line 423
bool
touches(string $relation)
Determine if the model touches a given relation.
in
HasRelationships at line 433
void
touchOwners()
Touch the owning relations of the model.
in
HasRelationships at line 458
protected array
getMorphs(string $name, string $type, string $id)
Get the polymorphic relationship columns.
in
HasRelationships at line 468
string
getMorphClass()
Get the class name for polymorphic relations.
in
HasRelationships at line 485
protected mixed
newRelatedInstance(string $class)
Create a new model instance for a related model.
in
HasRelationships at line 499
array
getRelations()
Get all the loaded relations for the instance.
in
HasRelationships at line 510
mixed
getRelation(string $relation)
Get a specified relationship.
in
HasRelationships at line 521
bool
relationLoaded(string $key)
Determine if the given relation is loaded.
in
HasRelationships at line 533
$this
setRelation(string $relation, mixed $value)
Set the specific relationship in the model.
in
HasRelationships at line 546
$this
setRelations(array $relations)
Set the entire relations array on the model.
in
HasRelationships at line 558
array
getTouchedRelations()
Get the relationships that are touched on save.
in
HasRelationships at line 569
$this
setTouchedRelations(array $touches)
Set the relationships that are touched on save.
in
HasTimestamps at line 21
bool
touch()
Update the model's update timestamp.
in
HasTimestamps at line 37
protected void
updateTimestamps()
Update the creation and update timestamps.
in
HasTimestamps at line 56
$this
setCreatedAt(mixed $value)
Set the value of the "created at" attribute.
in
HasTimestamps at line 69
$this
setUpdatedAt(mixed $value)
Set the value of the "updated at" attribute.
in
HasTimestamps at line 81
Carbon
freshTimestamp()
Get a fresh timestamp for the model.
in
HasTimestamps at line 91
string
freshTimestampString()
Get a fresh timestamp for the model.
in
HasTimestamps at line 101
bool
usesTimestamps()
Determine if the model uses timestamps.
in
HasTimestamps at line 111
string
getCreatedAtColumn()
Get the name of the "created at" column.
in
HasTimestamps at line 121
string
getUpdatedAtColumn()
Get the name of the "updated at" column.
in
HidesAttributes at line 26
array
getHidden()
Get the hidden attributes for the model.
in
HidesAttributes at line 37
$this
setHidden(array $hidden)
Set the hidden attributes for the model.
in
HidesAttributes at line 50
void
addHidden(array|string|null $attributes = null)
Add hidden attributes for the model.
in
HidesAttributes at line 62
array
getVisible()
Get the visible attributes for the model.
in
HidesAttributes at line 73
$this
setVisible(array $visible)
Set the visible attributes for the model.
in
HidesAttributes at line 86
void
addVisible(array|string|null $attributes = null)
Add visible attributes for the model.
in
HidesAttributes at line 99
$this
makeVisible(array|string $attributes)
Make the given, typically hidden, attributes visible.
in
HidesAttributes at line 116
$this
makeHidden(array|string $attributes)
Make the given, typically visible, attributes hidden.
in
GuardsAttributes at line 35
array
getFillable()
Get the fillable attributes for the model.
in
GuardsAttributes at line 46
$this
fillable(array $fillable)
Set the fillable attributes for the model.
in
GuardsAttributes at line 58
array
getGuarded()
Get the guarded attributes for the model.
in
GuardsAttributes at line 69
$this
guard(array $guarded)
Set the guarded attributes for the model.
in
GuardsAttributes at line 82
static void
unguard(bool $state = true)
Disable all mass assignable restrictions.
in
GuardsAttributes at line 92
static void
reguard()
Enable the mass assignment restrictions.
in
GuardsAttributes at line 102
static bool
isUnguarded()
Determine if current state is "unguarded".
in
GuardsAttributes at line 113
static mixed
unguarded(callable $callback)
Run the given callable while being unguarded.
in
GuardsAttributes at line 134
bool
isFillable(string $key)
Determine if the given attribute may be mass assigned.
in
GuardsAttributes at line 164
bool
isGuarded(string $key)
Determine if the given key is guarded.
in
GuardsAttributes at line 174
bool
totallyGuarded()
Determine if the model is totally guarded.
in
GuardsAttributes at line 185
protected array
fillableFromArray(array $attributes)
Get the fillable attributes of a given array.
at line 150
void
__construct(array $attributes = [])
Create a new Eloquent model instance.
at line 164
protected void
bootIfNotBooted()
Check if the model needs to be booted and if so, do it.
at line 182
static protected void
boot()
The "booting" method of the model.
at line 192
static protected void
bootTraits()
Boot all of the bootable traits on the model.
at line 208
static void
clearBootedModels()
Clear the list of booted models so they will be re-booted.
at line 223
$this
fill(array $attributes)
Fill the model with an array of attributes.
at line 249
$this
forceFill(array $attributes)
Fill the model with an array of attributes. Force mass assignment.
at line 262
protected string
removeTableFromKey(string $key)
Remove the table name from a given key.
at line 274
Model
newInstance(array $attributes = [], bool $exists = false)
Create a new instance of the given model.
at line 297
Model
newFromBuilder(array $attributes = [], string|null $connection = null)
Create a new model instance that is existing.
at line 314
static Builder
on(string|null $connection = null)
Begin querying the model on a given connection.
at line 331
static Builder
onWriteConnection()
Begin querying the model on the write connection.
at line 344
static Collection|Model[]
all(array|mixed $columns = ['*'])
Get all of the models from the database.
at line 357
static Builder|Model
with(array|string $relations)
Begin querying a model with eager loading.
at line 370
$this
load(array|string $relations)
Eager load relations on the model.
at line 389
protected int
increment(string $column, int $amount = 1, array $extra = [])
Increment a column's value by a given amount.
at line 402
protected int
decrement(string $column, int $amount = 1, array $extra = [])
Decrement a column's value by a given amount.
at line 416
protected int
incrementOrDecrement(string $column, int $amount, array $extra, string $method)
Run the increment or decrement method on the model.
at line 440
protected void
incrementOrDecrementAttributeValue(string $column, int $amount, array $extra, string $method)
Increment the underlying attribute value and sync with original.
at line 456
bool
update(array $attributes = [], array $options = [])
Update the model in the database.
at line 470
bool
push()
Save the model and all of its relationships.
at line 499
bool
save(array $options = [])
Save the model to the database.
at line 543
bool
saveOrFail(array $options = [])
Save the model to the database using transaction.
at line 556
protected void
finishSave(array $options)
Perform any actions that are necessary after the model is saved.
at line 573
protected bool
performUpdate(Builder $query)
Perform a model update operation.
at line 609
protected Builder
setKeysForSaveQuery(Builder $query)
Set the keys for a save update query.
at line 621
protected mixed
getKeyForSaveQuery()
Get the primary key value for a save query.
at line 634
protected bool
performInsert(Builder $query)
Perform a model insert operation.
at line 686
protected void
insertAndSetId(Builder $query, array $attributes)
Insert the given attributes and set the ID on the model.
at line 699
static int
destroy(array|int $ids)
Destroy the models for the given IDs.
at line 729
bool|null
delete()
Delete the model from the database.
at line 770
bool|null
forceDelete()
Force a hard delete on a soft deleted model.
This method protects developers from running forceDelete when trait is missing.
at line 780
protected void
performDeleteOnModel()
Perform the actual delete query on this model instance.
at line 790
static Builder
query()
Begin querying the model.
at line 800
Builder
newQuery()
Get a new query builder for the model's table.
at line 816
Builder|Model
newQueryWithoutScopes()
Get a new query builder that doesn't have any global scopes.
at line 834
Builder
newQueryWithoutScope(Scope|string $scope)
Get a new query instance without a given scope.
at line 847
Builder|Model
newEloquentBuilder(Builder $query)
Create a new Eloquent query builder for the model.
at line 857
protected Builder
newBaseQueryBuilder()
Get a new query builder instance for the connection.
at line 872
Collection
newCollection(array $models = [])
Create a new Eloquent Collection instance.
at line 887
Pivot
newPivot(Model $parent, array $attributes, string $table, bool $exists, string|null $using = null)
Create a new pivot model instance.
at line 898
array
toArray()
Convert the model instance to an array.
at line 911
string
toJson(int $options = 0)
Convert the model instance to JSON.
at line 927
array
jsonSerialize()
Convert the object into something JSON serializable.
at line 938
Model|null
fresh(array|string $with = [])
Reload a fresh model instance from the database.
at line 955
$this
refresh()
Reload the current model instance with fresh attributes from the database.
at line 974
Model
replicate(array $except = null)
Clone the model into a new, non-existing instance.
at line 999
bool
is(Model $model)
Determine if two models have the same ID and belong to the same table.
at line 1012
bool
isNot(Model $model)
Determine if two models are not the same.
at line 1022
Connection
getConnection()
Get the database connection for the model.
at line 1032
string
getConnectionName()
Get the current connection name for the model.
at line 1043
$this
setConnection(string $name)
Set the connection associated with the model.
at line 1056
static Connection
resolveConnection(string|null $connection = null)
Resolve a connection instance.
at line 1066
static ConnectionResolverInterface
getConnectionResolver()
Get the connection resolver instance.
at line 1077
static void
setConnectionResolver(ConnectionResolverInterface $resolver)
Set the connection resolver instance.
at line 1087
static void
unsetConnectionResolver()
Unset the connection resolver for models.
at line 1097
string
getTable()
Get the table associated with the model.
at line 1112
$this
setTable(string $table)
Set the table associated with the model.
at line 1124
string
getKeyName()
Get the primary key for the model.
at line 1135
$this
setKeyName(string $key)
Set the primary key for the model.
at line 1147
string
getQualifiedKeyName()
Get the table qualified key name.
at line 1157
string
getKeyType()
Get the auto-incrementing key type.
at line 1168
$this
setKeyType(string $type)
Set the data type for the primary key.
at line 1180
bool
getIncrementing()
Get the value indicating whether the IDs are incrementing.
at line 1191
$this
setIncrementing(bool $value)
Set whether IDs are incrementing.
at line 1203
mixed
getKey()
Get the value of the model's primary key.
at line 1213
mixed
getQueueableId()
Get the queueable identity for the entity.
at line 1223
mixed
getRouteKey()
Get the value of the model's route key.
at line 1233
string
getRouteKeyName()
Get the route key for the model.
at line 1243
string
getForeignKey()
Get the default foreign key name for the model.
at line 1253
int
getPerPage()
Get the number of models to return per page.
at line 1264
$this
setPerPage(int $perPage)
Set the number of models to return per page.
at line 1277
mixed
__get(string $key)
Dynamically retrieve attributes on the model.
at line 1289
void
__set(string $key, mixed $value)
Dynamically set attributes on the model.
at line 1300
bool
offsetExists(mixed $offset)
Determine if the given attribute exists.
at line 1311
mixed
offsetGet(mixed $offset)
Get the value for a given offset.
at line 1323
void
offsetSet(mixed $offset, mixed $value)
Set the value for a given offset.
at line 1334
void
offsetUnset(mixed $offset)
Unset the value for a given offset.
at line 1345
bool
__isset(string $key)
Determine if an attribute or relation exists on the model.
at line 1356
void
__unset(string $key)
Unset an attribute on the model.
at line 1368
mixed
__call(string $method, array $parameters)
Handle dynamic method calls into the model.
at line 1384
static mixed
__callStatic(string $method, array $parameters)
Handle dynamic static method calls into the method.
at line 1394
string
__toString()
Convert the model to its string representation.
at line 1404
void
__wakeup()
When a model is being unserialized, check if it needs to be booted.