Model
class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializable, QueueableEntity, UrlRoutable (View source)
Constants
CREATED_AT |
The name of the "created at" column. |
UPDATED_AT |
The name of the "updated at" column. |
Properties
Methods
Create a new Eloquent model instance.
Clear the list of booted models so they will be re-booted.
Register a new global scope on the model.
Get the global scopes for this class instance.
Register an observer with the Model.
Fill the model with an array of attributes.
Fill the model with an array of attributes. Force mass assignment.
Create a new instance of the given model.
Create a new model instance that is existing.
Create a collection of models from plain arrays.
Create a collection of models from a raw query.
Save a new model and return the instance. Allow mass-assignment.
Begin querying the model on the write connection.
Get all of the models from the database.
Reload a fresh model instance from the database.
Eager load relations on the model.
Append attributes to query when building a query.
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.
Retrieve the fully qualified class name from a slug.
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 joining table name for a many-to-many relation.
Destroy the models for the given IDs.
Delete the model from the database.
Force a hard delete on a soft deleted model.
Remove all of the event listeners for the model.
Get the observable event names.
Set the observable event names.
Add an observable event name.
Remove an observable event name.
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.
Touch the owning relations of the model.
Determine if the model touches a given relation.
Update the model's update timestamp.
Set the value of the "created at" attribute.
Set the value of the "updated at" attribute.
Get the name of the "created at" column.
Get the name of the "updated at" column.
Get a fresh timestamp for the model.
Get a fresh timestamp for the model.
Get a new query builder that doesn't have any global scopes.
Create a new Eloquent Collection instance.
Get the table associated with the model.
Set the table associated with the model.
Get the value of the model's primary key.
Get the queueable identity for the entity.
Get the primary key for the model.
Set the primary key for the model.
Get the table qualified key name.
Get the value of the model's route key.
Get the route key for the model.
Determine if the model uses timestamps.
Get the class name for polymorphic relations.
Get the number of models to return per page.
Set the number of models to return per page.
Get the default foreign key name for the model.
Get the hidden attributes for the model.
Set the hidden attributes for the model.
Add hidden attributes for the model.
Make the given, typically hidden, attributes visible.
Make the given, typically hidden, attributes visible.
Get the visible attributes for the model.
Set the visible attributes for the model.
Add visible attributes for the model.
Set the accessors to append to model arrays.
Get the fillable attributes for the model.
Set the fillable attributes for the model.
Get the guarded attributes for the model.
Set the guarded attributes for the model.
Disable all mass assignable restrictions.
Enable the mass assignment restrictions.
Determine if current state is "unguarded".
Run the given callable while being unguarded.
Determine if the given attribute may be mass assigned.
Determine if the given key is guarded.
Determine if the model is totally guarded.
Get the relationships that are touched on save.
Set the relationships that are touched on save.
Get the value indicating whether the IDs are incrementing.
Set whether IDs are incrementing.
Convert the model instance to JSON.
Convert the object into something JSON serializable.
Convert the model instance to an array.
Convert the model's attributes to an array.
Get the model's relationships in array form.
Get an attribute from the model.
Get a plain attribute (not a relationship).
Get a relationship.
Determine if a get mutator exists for an attribute.
Determine whether an attribute should be cast to a native type.
Get the casts array.
Set a given attribute on the model.
Determine if a set mutator exists for an attribute.
Get the attributes that should be converted to dates.
Set the date format used by the model.
Decode the given JSON back into an array or object.
Get all of the current attributes on the model.
Set the array of model attributes. No checking is done.
Get the model's original attribute values.
Sync the original attributes with the current.
Sync a single original attribute with its current value.
Determine if the model or given attribute(s) have been modified.
Get the attributes that have been changed since last sync.
Get all the loaded relations for the instance.
Get a specified relationship.
Determine if the given relation is loaded.
Set the specific relationship in the model.
Set the entire relations array on the model.
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 event dispatcher instance.
Unset the event dispatcher for models.
Get the mutated attributes for a given instance.
Extract and cache all the mutated attributes of a class.
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 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
at line line 275
void
__construct(
array $attributes = array())
Create a new Eloquent model instance.
at line line 333
static
void
clearBootedModels()
Clear the list of booted models so they will be re-booted.
at line line 348
static
mixed
addGlobalScope(
Scope|Closure|string $scope,
Closure $implementation = null)
Register a new global scope on the model.
at line line 371
static
bool
hasGlobalScope(
Scope|string $scope)
Determine if a model has a global scope.
at line line 382
static
Scope|Closure|null
getGlobalScope(
Scope|string $scope)
Get a global scope registered with the model.
at line line 412
static
void
observe(
object|string $class,
int $priority)
Register an observer with the Model.
at line line 462
$this
forceFill(
array $attributes)
Fill the model with an array of attributes. Force mass assignment.
at line line 496
Model
newInstance(
array $attributes = array(),
bool $exists = false)
Create a new instance of the given model.
at line line 515
Model
newFromBuilder(
array $attributes = array(),
string|null $connection = null)
Create a new model instance that is existing.
at line line 533
static
Collection
hydrate(
array $items,
string|null $connection = null)
Create a collection of models from plain arrays.
at line line 552
static
Collection
hydrateRaw(
string $query,
array $bindings = array(),
string|null $connection = null)
Create a collection of models from a raw query.
at line line 567
static
Model
create(
array $attributes = array())
Save a new model and return the instance.
at line line 582
static
Model
forceCreate(
array $attributes)
Save a new model and return the instance. Allow mass-assignment.
at line line 610
static
Builder
on(
string|null $connection = null)
Begin querying the model on a given connection.
at line line 627
static
Builder
onWriteConnection()
Begin querying the model on the write connection.
at line line 640
static
Collection|Model[]
all(
array|mixed $columns = array('*'))
Get all of the models from the database.
at line line 655
$this|null
fresh(
array|string $with = array())
Reload a fresh model instance from the database.
at line line 691
static
Builder|Model
with(
array|string $relations)
Begin querying a model with eager loading.
at line line 708
$this
append(
array|string $attributes)
Append attributes to query when building a query.
at line line 729
HasOne
hasOne(
string $related,
string $foreignKey = null,
string $localKey = null)
Define a one-to-one relationship.
at line line 750
MorphOne
morphOne(
string $related,
string $name,
string $type = null,
string $id = null,
string $localKey = null)
Define a polymorphic one-to-one relationship.
at line line 772
BelongsTo
belongsTo(
string $related,
string $foreignKey = null,
string $otherKey = null,
string $relation = null)
Define an inverse one-to-one or many relationship.
at line line 810
MorphTo
morphTo(
string $name = null,
string $type = null,
string $id = null)
Define a polymorphic, inverse one-to-one or many relationship.
at line line 852
string
getActualClassNameForMorph(
string $class)
Retrieve the fully qualified class name from a slug.
at line line 865
HasMany
hasMany(
string $related,
string $foreignKey = null,
string $localKey = null)
Define a one-to-many relationship.
at line line 886
HasManyThrough
hasManyThrough(
string $related,
string $through,
string|null $firstKey = null,
string|null $secondKey = null,
string|null $localKey = null)
Define a has-many-through relationship.
at line line 909
MorphMany
morphMany(
string $related,
string $name,
string $type = null,
string $id = null,
string $localKey = null)
Define a polymorphic one-to-many relationship.
at line line 935
BelongsToMany
belongsToMany(
string $related,
string $table = null,
string $foreignKey = null,
string $otherKey = null,
string $relation = null)
Define a many-to-many relationship.
at line line 979
MorphToMany
morphToMany(
string $related,
string $name,
string $table = null,
string $foreignKey = null,
string $otherKey = null,
bool $inverse = false)
Define a polymorphic many-to-many relationship.
at line line 1015
MorphToMany
morphedByMany(
string $related,
string $name,
string $table = null,
string $foreignKey = null,
string $otherKey = null)
Define a polymorphic, inverse many-to-many relationship.
at line line 1051
string
joiningTable(
string $related)
Get the joining table name for a many-to-many relation.
at line line 1144
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 line 1166
static
void
saving(
Closure|string $callback,
int $priority)
Register a saving model event with the dispatcher.
at line line 1178
static
void
saved(
Closure|string $callback,
int $priority)
Register a saved model event with the dispatcher.
at line line 1190
static
void
updating(
Closure|string $callback,
int $priority)
Register an updating model event with the dispatcher.
at line line 1202
static
void
updated(
Closure|string $callback,
int $priority)
Register an updated model event with the dispatcher.
at line line 1214
static
void
creating(
Closure|string $callback,
int $priority)
Register a creating model event with the dispatcher.
at line line 1226
static
void
created(
Closure|string $callback,
int $priority)
Register a created model event with the dispatcher.
at line line 1238
static
void
deleting(
Closure|string $callback,
int $priority)
Register a deleting model event with the dispatcher.
at line line 1250
static
void
deleted(
Closure|string $callback,
int $priority)
Register a deleted model event with the dispatcher.
at line line 1260
static
void
flushEventListeners()
Remove all of the event listeners for the model.
at line line 1339
void
removeObservableEvents(
array|mixed $observables)
Remove an observable event name.
at line line 1416
bool|int
update(
array $attributes = array(),
array $options = array())
Update the model in the database.
at line line 1499
bool
saveOrFail(
array $options = array())
Save the model to the database using transaction.
at line line 1831
Builder
newQueryWithoutScope(
Scope|string $scope)
Get a new query instance without a given scope.
at line line 1843
Builder|Model
newQueryWithoutScopes()
Get a new query builder that doesn't have any global scopes.
at line line 1861
Builder|Model
newEloquentBuilder(
Builder $query)
Create a new Eloquent query builder for the model.
at line line 1886
Collection
newCollection(
array $models = array())
Create a new Eloquent Collection instance.
at line line 1900
Pivot
newPivot(
Model $parent,
array $attributes,
string $table,
bool $exists)
Create a new pivot model instance.
at line line 2112
void
addHidden(
array|string|null $attributes = null)
Add hidden attributes for the model.
at line line 2125
$this
makeVisible(
array|string $attributes)
Make the given, typically hidden, attributes visible.
at line line 2140
$this
withHidden(
array|string $attributes)
Make the given, typically hidden, attributes visible.
at line line 2174
void
addVisible(
array|string|null $attributes = null)
Add visible attributes for the model.
at line line 2246
static
void
unguard(
bool $state = true)
Disable all mass assignable restrictions.
at line line 2277
static
mixed
unguarded(
callable $callback)
Run the given callable while being unguarded.
at line line 2298
bool
isFillable(
string $key)
Determine if the given attribute may be mass assigned.
at line line 2370
$this
setTouchedRelations(
array $touches)
Set the relationships that are touched on save.
at line line 2706
bool
hasGetMutator(
string $key)
Determine if a get mutator exists for an attribute.
at line line 2744
bool
hasCast(
string $key,
array|string|null $types = null)
Determine whether an attribute should be cast to a native type.
at line line 2852
$this
setAttribute(
string $key,
mixed $value)
Set a given attribute on the model.
at line line 2885
bool
hasSetMutator(
string $key)
Determine if a set mutator exists for an attribute.
at line line 2908
string
fromDateTime(
DateTime|int $value)
Convert a DateTime to a storable string.
at line line 3024
mixed
fromJson(
string $value,
bool $asObject = false)
Decode the given JSON back into an array or object.
at line line 3035
Model
replicate(
array $except = null)
Clone the model into a new, non-existing instance.
at line line 3069
$this
setRawAttributes(
array $attributes,
bool $sync = false)
Set the array of model attributes. No checking is done.
at line line 3087
mixed|array
getOriginal(
string|null $key = null,
mixed $default = null)
Get the model's original attribute values.
at line line 3110
$this
syncOriginalAttribute(
string $attribute)
Sync a single original attribute with its current value.
at line line 3123
bool
isDirty(
array|string|null $attributes = null)
Determine if the model or given attribute(s) have been modified.
at line line 3219
$this
setRelation(
string $relation,
mixed $value)
Set the specific relationship in the model.
at line line 3232
$this
setRelations(
array $relations)
Set the entire relations array on the model.
at line line 3278
static
Connection
resolveConnection(
string|null $connection = null)
Resolve a connection instance.
at line line 3288
static
ConnectionResolverInterface
getConnectionResolver()
Get the connection resolver instance.
at line line 3299
static
void
setConnectionResolver(
ConnectionResolverInterface $resolver)
Set the connection resolver instance.
at line line 3330
static
void
setEventDispatcher(
Dispatcher $dispatcher)
Set the event dispatcher instance.
at line line 3367
static
void
cacheMutatedAttributes(
string $class)
Extract and cache all the mutated attributes of a class.
at line line 3485
mixed
__call(
string $method,
array $parameters)
Handle dynamic method calls into the model.
at line line 3503
static
mixed
__callStatic(
string $method,
array $parameters)
Handle dynamic static method calls into the method.
at line line 3525
void
__wakeup()
When a model is being unserialized, check if it needs to be booted.