Model
Implements
- Arrayable
- ArrayAccess
- CanBeEscapedWhenCastToString
- HasBroadcastChannel
- Jsonable
- JsonSerializable
- QueueableEntity
- UrlRoutable
Uses
- HasAttributes
- HasEvents
- HasGlobalScopes
- HasRelationships
- HasTimestamps
- HidesAttributes
- GuardsAttributes
- ForwardsCalls
Constants
CREATED_AT string|null
The name of the "created at" column.
UPDATED_AT string|null
The name of the "updated at" column.
Properties
$connection string|null
The connection name for the model.
$table string
The table associated with the model.
$primaryKey string
The primary key for the model.
$keyType string
The "type" of the primary key ID.
$incrementing bool
Indicates if the IDs are auto-incrementing.
$with array
The relations to eager load on every query.
$withCount array
The relationship counts that should be eager loaded on every query.
$preventsLazyLoading bool
Indicates whether lazy loading will be prevented on this model.
$perPage int
The number of models to return for pagination.
$exists bool
Indicates if the model exists.
$wasRecentlyCreated bool
Indicates if the model was inserted during the current request lifecycle.
$escapeWhenCastingToString bool
Indicates that the object's string representation should be escaped when __toString is invoked.
$resolver ConnectionResolverInterface
The connection resolver instance.
$booted array
The array of booted models.
$traitInitializers array
The array of trait initializers that will be called on each new instance.
$globalScopes array
The array of global scopes on the model.
$ignoreOnTouch array
The list of models classes that should not be affected with touch.
$modelsShouldPreventLazyLoading bool
Indicates whether lazy loading should be restricted on all models.
$lazyLoadingViolationCallback callable|null
The callback that is responsible for handling lazy loading violations.
$isBroadcasting bool
Indicates if broadcasting is currently enabled.
Methods
__construct ( array $attributes ) : void
Create a new Eloquent model instance.
Parameters
- $attributes array
bootIfNotBooted ( ) : void
Check if the model needs to be booted and if so, do it.
booting ( ) : void
Perform any actions required before the model boots.
boot ( ) : void
Bootstrap the model and its traits.
bootTraits ( ) : void
Boot all of the bootable traits on the model.
initializeTraits ( ) : void
Initialize any initializable traits on the model.
booted ( ) : void
Perform any actions required after the model boots.
clearBootedModels ( ) : void
Clear the list of booted models so they will be re-booted.
withoutTouching ( callable $callback ) : void
Disables relationship model touching for the current class during given callback scope.
Parameters
- $callback callable
withoutTouchingOn ( array $models , callable $callback ) : void
Disables relationship model touching for the given model classes during given callback scope.
Parameters
- $models array
- $callback callable
isIgnoringTouch ( $class ) : bool
Determine if the given model is ignoring touches.
Parameters
- $class string|null
preventLazyLoading ( $value ) : void
Prevent model relationships from being lazy loaded.
Parameters
- $value bool
handleLazyLoadingViolationUsing ( callable $callback ) : void
Register a callback that is responsible for handling lazy loading violations.
Parameters
- $callback callable|null
withoutBroadcasting ( callable $callback ) : mixed
Execute a callback without broadcasting any model events for all model types.
Parameters
- $callback callable
fill ( array $attributes ) : $this
Fill the model with an array of attributes.
Parameters
- $attributes array
forceFill ( array $attributes ) : $this
Fill the model with an array of attributes. Force mass assignment.
Parameters
- $attributes array
qualifyColumn ( $column ) : string
Qualify the given column name by the model's table.
Parameters
- $column string
qualifyColumns ( $columns ) : array
Qualify the given columns with the model's table.
Parameters
- $columns array
newInstance ( $attributes , $exists ) : static
Create a new instance of the given model.
Parameters
- $attributes array
- $exists bool
newFromBuilder ( $attributes , $connection ) : static
Create a new model instance that is existing.
Parameters
- $attributes array
- $connection string|null
on ( $connection ) : Builder
Begin querying the model on a given connection.
Parameters
- $connection string|null
all ( $columns ) : Collection |static[]
Get all of the models from the database.
Parameters
- $columns array|mixed
with ( $relations ) : Builder
Begin querying a model with eager loading.
Parameters
- $relations array|string
load ( $relations ) : $this
Eager load relations on the model.
Parameters
- $relations array|string
loadMorph ( $relation , $relations ) : $this
Eager load relationships on the polymorphic relation of a model.
Parameters
- $relation string
- $relations array
loadMissing ( $relations ) : $this
Eager load relations on the model if they are not already eager loaded.
Parameters
- $relations array|string
loadAggregate ( $relations , $column , $function ) : $this
Eager load relation's column aggregations on the model.
Parameters
- $relations array|string
- $column string
- $function string
loadCount ( $relations ) : $this
Eager load relation counts on the model.
Parameters
- $relations array|string
loadMax ( $relations , $column ) : $this
Eager load relation max column values on the model.
Parameters
- $relations array|string
- $column string
loadMin ( $relations , $column ) : $this
Eager load relation min column values on the model.
Parameters
- $relations array|string
- $column string
loadSum ( $relations , $column ) : $this
Eager load relation's column summations on the model.
Parameters
- $relations array|string
- $column string
loadAvg ( $relations , $column ) : $this
Eager load relation average column values on the model.
Parameters
- $relations array|string
- $column string
loadExists ( $relations ) : $this
Eager load related model existence values on the model.
Parameters
- $relations array|string
loadMorphAggregate ( $relation , $relations , $column , $function ) : $this
Eager load relationship column aggregation on the polymorphic relation of a model.
Parameters
- $relation string
- $relations array
- $column string
- $function string
loadMorphCount ( $relation , $relations ) : $this
Eager load relationship counts on the polymorphic relation of a model.
Parameters
- $relation string
- $relations array
loadMorphMax ( $relation , $relations , $column ) : $this
Eager load relationship max column values on the polymorphic relation of a model.
Parameters
- $relation string
- $relations array
- $column string
loadMorphMin ( $relation , $relations , $column ) : $this
Eager load relationship min column values on the polymorphic relation of a model.
Parameters
- $relation string
- $relations array
- $column string
loadMorphSum ( $relation , $relations , $column ) : $this
Eager load relationship column summations on the polymorphic relation of a model.
Parameters
- $relation string
- $relations array
- $column string
loadMorphAvg ( $relation , $relations , $column ) : $this
Eager load relationship average column values on the polymorphic relation of a model.
Parameters
- $relation string
- $relations array
- $column string
increment ( $column , $amount , array $extra ) : int
Increment a column's value by a given amount.
Parameters
- $column string
- $amount float|int
- $extra array
decrement ( $column , $amount , array $extra ) : int
Decrement a column's value by a given amount.
Parameters
- $column string
- $amount float|int
- $extra array
incrementOrDecrement ( $column , $amount , $extra , $method ) : int
Run the increment or decrement method on the model.
Parameters
- $column string
- $amount float|int
- $extra array
- $method string
update ( array $attributes , array $options ) : bool
Update the model in the database.
Parameters
- $attributes array
- $options array
updateOrFail ( array $attributes , array $options ) : bool
Update the model in the database within a transaction.
Parameters
- $attributes array
- $options array
updateQuietly ( array $attributes , array $options ) : bool
Update the model in the database without raising any events.
Parameters
- $attributes array
- $options array
push ( ) : bool
Save the model and all of its relationships.
saveQuietly ( array $options ) : bool
Save the model to the database without raising any events.
Parameters
- $options array
save ( array $options ) : bool
Save the model to the database.
Parameters
- $options array
saveOrFail ( array $options ) : bool
Save the model to the database within a transaction.
Parameters
- $options array
finishSave ( array $options ) : void
Perform any actions that are necessary after the model is saved.
Parameters
- $options array
performUpdate ( Builder $query ) : bool
Perform a model update operation.
Parameters
- $query Builder
setKeysForSelectQuery ( $query ) : Builder
Set the keys for a select query.
Parameters
- $query Builder
getKeyForSelectQuery ( ) : mixed
Get the primary key value for a select query.
setKeysForSaveQuery ( $query ) : Builder
Set the keys for a save update query.
Parameters
- $query Builder
getKeyForSaveQuery ( ) : mixed
Get the primary key value for a save query.
performInsert ( Builder $query ) : bool
Perform a model insert operation.
Parameters
- $query Builder
insertAndSetId ( Builder $query , $attributes ) : void
Insert the given attributes and set the ID on the model.
Parameters
- $query Builder
- $attributes array
destroy ( $ids ) : int
Destroy the models for the given IDs.
Parameters
- $ids Collection |array|int|string
delete ( ) : bool|null
Delete the model from the database.
deleteOrFail ( ) : bool|null
Delete the model from the database within a transaction.
forceDelete ( ) : bool|null
Force a hard delete on a soft deleted model.
performDeleteOnModel ( ) : void
Perform the actual delete query on this model instance.
newModelQuery ( ) : Builder |static
Get a new query builder that doesn't have any global scopes or eager loading.
newQueryWithoutRelationships ( ) : Builder
Get a new query builder with no relationships loaded.
registerGlobalScopes ( $builder ) : Builder
Register the global scopes for this builder instance.
Parameters
- $builder Builder
newQueryWithoutScopes ( ) : Builder |static
Get a new query builder that doesn't have any global scopes.
newQueryWithoutScope ( $scope ) : Builder
Get a new query instance without a given scope.
Parameters
- $scope Scope |string
newQueryForRestoration ( $ids ) : Builder
Get a new query to restore one or more models by their queueable IDs.
Parameters
- $ids array|int
newEloquentBuilder ( $query ) : Builder |static
Create a new Eloquent query builder for the model.
Parameters
- $query Builder
newCollection ( array $models ) : Collection
Create a new Eloquent Collection instance.
Parameters
- $models array
newPivot ( $parent , array $attributes , $table , $exists , $using ) : Pivot
Create a new pivot model instance.
Parameters
- $parent Model
- $attributes array
- $table string
- $exists bool
- $using string|null
hasNamedScope ( $scope ) : bool
Determine if the model has a given scope.
Parameters
- $scope string
callNamedScope ( $scope , array $parameters ) : mixed
Apply the given named scope if possible.
Parameters
- $scope string
- $parameters array
toArray ( ) : array
Convert the model instance to an array.
toJson ( $options ) : string
Convert the model instance to JSON.
Parameters
- $options int
jsonSerialize ( ) : array
Convert the object into something JSON serializable.
fresh ( $with ) : static|null
Reload a fresh model instance from the database.
Parameters
- $with array|string
refresh ( ) : $this
Reload the current model instance with fresh attributes from the database.
replicate ( array $except ) : static
Clone the model into a new, non-existing instance.
Parameters
- $except array|null
is ( $model ) : bool
Determine if two models have the same ID and belong to the same table.
Parameters
- $model Model |null
isNot ( $model ) : bool
Determine if two models are not the same.
Parameters
- $model Model |null
getConnectionName ( ) : string|null
Get the current connection name for the model.
setConnection ( $name ) : $this
Set the connection associated with the model.
Parameters
- $name string|null
resolveConnection ( $connection ) : Connection
Resolve a connection instance.
Parameters
- $connection string|null
getConnectionResolver ( ) : ConnectionResolverInterface
Get the connection resolver instance.
setConnectionResolver ( ConnectionResolverInterface $resolver ) : void
Set the connection resolver instance.
Parameters
- $resolver ConnectionResolverInterface
unsetConnectionResolver ( ) : void
Unset the connection resolver for models.
getTable ( ) : string
Get the table associated with the model.
setTable ( $table ) : $this
Set the table associated with the model.
Parameters
- $table string
getKeyName ( ) : string
Get the primary key for the model.
setKeyName ( $key ) : $this
Set the primary key for the model.
Parameters
- $key string
getQualifiedKeyName ( ) : string
Get the table qualified key name.
getKeyType ( ) : string
Get the auto-incrementing key type.
setKeyType ( $type ) : $this
Set the data type for the primary key.
Parameters
- $type string
getIncrementing ( ) : bool
Get the value indicating whether the IDs are incrementing.
setIncrementing ( $value ) : $this
Set whether IDs are incrementing.
Parameters
- $value bool
getKey ( ) : mixed
Get the value of the model's primary key.
getQueueableId ( ) : mixed
Get the queueable identity for the entity.
getQueueableRelations ( ) : array
Get the queueable relationships for the entity.
getQueueableConnection ( ) : string|null
Get the queueable connection for the entity.
getRouteKey ( ) : mixed
Get the value of the model's route key.
getRouteKeyName ( ) : string
Get the route key for the model.
resolveRouteBinding ( $value , $field ) : Model |null
Retrieve the model for a bound value.
Parameters
- $value mixed
- $field string|null
resolveSoftDeletableRouteBinding ( $value , $field ) : Model |null
Retrieve the model for a bound value.
Parameters
- $value mixed
- $field string|null
resolveChildRouteBinding ( $childType , $value , $field ) : Model |null
Retrieve the child model for a bound value.
Parameters
- $childType string
- $value mixed
- $field string|null
resolveSoftDeletableChildRouteBinding ( $childType , $value , $field ) : Model |null
Retrieve the child model for a bound value.
Parameters
- $childType string
- $value mixed
- $field string|null
resolveChildRouteBindingQuery ( $childType , $value , $field ) : Relation
Retrieve the child model query for a bound value.
Parameters
- $childType string
- $value mixed
- $field string|null
resolveRouteBindingQuery ( $query , $value , $field ) : Relation
Retrieve the model for a bound value.
Parameters
getForeignKey ( ) : string
Get the default foreign key name for the model.
getPerPage ( ) : int
Get the number of models to return per page.
setPerPage ( $perPage ) : $this
Set the number of models to return per page.
Parameters
- $perPage int
preventsLazyLoading ( ) : bool
Determine if lazy loading is disabled.
broadcastChannelRoute ( ) : string
Get the broadcast channel route definition that is associated with the given entity.
broadcastChannel ( ) : string
Get the broadcast channel name that is associated with the given entity.
__get ( $key ) : mixed
Dynamically retrieve attributes on the model.
Parameters
- $key string
__set ( $key , $value ) : void
Dynamically set attributes on the model.
Parameters
- $key string
- $value mixed
offsetExists ( $offset ) : bool
Determine if the given attribute exists.
Parameters
- $offset mixed
offsetGet ( $offset ) : mixed
Get the value for a given offset.
Parameters
- $offset mixed
offsetSet ( $offset , $value ) : void
Set the value for a given offset.
Parameters
- $offset mixed
- $value mixed
offsetUnset ( $offset ) : void
Unset the value for a given offset.
Parameters
- $offset mixed
__isset ( $key ) : bool
Determine if an attribute or relation exists on the model.
Parameters
- $key string
__unset ( $key ) : void
Unset an attribute on the model.
Parameters
- $key string
__call ( $method , $parameters ) : mixed
Handle dynamic method calls into the model.
Parameters
- $method string
- $parameters array
__callStatic ( $method , $parameters ) : mixed
Handle dynamic static method calls into the model.
Parameters
- $method string
- $parameters array
__toString ( ) : string
Convert the model to its string representation.
escapeWhenCastingToString ( $escape ) : $this
Indicate that the object's string representation should be escaped when __toString is invoked.
Parameters
- $escape bool
__sleep ( ) : array
Prepare the object for serialization.
__wakeup ( ) : void
When a model is being unserialized, check if it needs to be booted.