Pivot

class Pivot extends Model (View source)

Constants

CREATED_AT

The name of the "created at" column.

UPDATED_AT

The name of the "updated at" column.

Properties

protected string $connection The connection name for the model. from Model
protected string $table The table associated with the model. from Model
protected string $primaryKey The primary key for the model. from Model
protected int $perPage The number of models to return for pagination. from Model
bool $incrementing Indicates if the IDs are auto-incrementing. from Model
bool $timestamps Indicates if the model should be timestamped. from Model
protected array $attributes The model's attributes. from Model
protected array $original The model attribute's original state. from Model
protected array $relations The loaded relationships for the model. from Model
protected array $hidden The attributes that should be hidden for arrays. from Model
protected array $visible The attributes that should be visible in arrays. from Model
protected array $appends The accessors to append to the model's array form. from Model
protected array $fillable The attributes that are mass assignable. from Model
protected array $guarded The attributes that aren't mass assignable.
protected array $dates The attributes that should be mutated to dates. from Model
protected array $touches The relationships that should be touched on save. from Model
protected array $observables User exposed observable events from Model
protected array $with The relations to eager load on every query. from Model
protected string $morphClass The class name to be used in polymorphic relations. from Model
bool $exists Indicates if the model exists. from Model
static bool $snakeAttributes Indicates whether attributes are snake cased on arrays. from Model
static protected ConnectionResolverInterface $resolver The connection resolver instance. from Model
static protected Dispatcher $dispatcher The event dispatcher instance. from Model
static protected array $booted The array of booted models. from Model
static protected array $globalScopes The array of global scopes on the model. from Model
static protected bool $unguarded Indicates if all mass assignment is enabled. from Model
static protected array $mutatorCache The cache of the mutated attributes for each class. from Model
static array $manyMethods The many to many relationship methods. from Model
protected Model $parent The parent model of the relationship.
protected string $foreignKey The name of the foreign key column.
protected string $otherKey The name of the "other key" column.

Methods

void __construct(Model $parent, array $attributes, string $table, bool $exists = false)

Create a new pivot model instance.

void bootIfNotBooted()

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

from Model
static void boot()

The "booting" method of the model.

from Model
static void bootTraits()

Boot all of the bootable traits on the model.

from Model
static void addGlobalScope(ScopeInterface $scope)

Register a new global scope on the model.

from Model
static bool hasGlobalScope(ScopeInterface $scope)

Determine if a model has a global scope.

from Model
static ScopeInterface|null getGlobalScope(ScopeInterface $scope)

Get a global scope registered with the model.

from Model
ScopeInterface[] getGlobalScopes()

Get the global scopes for this class instance.

from Model
static void observe(object $class)

Register an observer with the Model.

from Model
$this fill(array $attributes)

Fill the model with an array of attributes.

from Model
array fillableFromArray(array $attributes)

Get the fillable attributes of a given array.

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

Create a new instance of the given model.

from Model
Model newFromBuilder(array $attributes = array())

Create a new model instance that is existing.

from Model
static Collection hydrate(array $items, string $connection = null)

Create a collection of models from plain arrays.

from Model
static Collection hydrateRaw(string $query, array $bindings = array(), string $connection = null)

Create a collection of models from a raw query.

from Model
static Model create(array $attributes)

Save a new model and return the instance.

from Model
static Model firstOrCreate(array $attributes)

Get the first record matching the attributes or create it.

from Model
static Model firstOrNew(array $attributes)

Get the first record matching the attributes or instantiate it.

from Model
static Model updateOrCreate(array $attributes, array $values = array())

Create or update a record matching the attributes, and fill it with values.

from Model
static Model|null firstByAttributes(array $attributes)

Get the first model for the given attributes.

from Model
static Builder query()

Begin querying the model.

from Model
static Builder on(string $connection = null)

Begin querying the model on a given connection.

from Model
static Builder onWriteConnection()

Begin querying the model on the write connection.

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

Get all of the models from the database.

from Model
static Collection|Model|null find(mixed $id, array $columns = array('*'))

Find a model by its primary key.

from Model
static Collection|Model findOrNew(mixed $id, array $columns = array('*'))

Find a model by its primary key or return new static.

from Model
static Collection|Model findOrFail(mixed $id, array $columns = array('*'))

Find a model by its primary key or throw an exception.

from Model
$this load(array|string $relations)

Eager load relations on the model.

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

Being querying a model with eager loading.

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

Define a one-to-one relationship.

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

Define a polymorphic one-to-one relationship.

from Model
BelongsTo belongsTo(string $related, string $foreignKey = null, string $otherKey = null, string $relation = null)

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

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

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

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

Define a one-to-many relationship.

from Model
HasManyThrough hasManyThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null)

Define a has-many-through relationship.

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

Define a polymorphic one-to-many relationship.

from Model
BelongsToMany belongsToMany(string $related, string $table = null, string $foreignKey = null, string $otherKey = null, string $relation = null)

Define a many-to-many relationship.

from Model
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.

from Model
MorphToMany morphedByMany(string $related, string $name, string $table = null, string $foreignKey = null, string $otherKey = null)

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

from Model
string getBelongsToManyCaller()

Get the relationship name of the belongs to many.

from Model
string joiningTable(string $related)

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

from Model
static int destroy(array|int $ids)

Destroy the models for the given IDs.

from Model
bool|null delete()

Delete the pivot model record from the database.

void forceDelete()

Force a hard delete on a soft deleted model.

from Model
void performDeleteOnModel()

Perform the actual delete query on this model instance.

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

Register a saving model event with the dispatcher.

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

Register a saved model event with the dispatcher.

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

Register an updating model event with the dispatcher.

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

Register an updated model event with the dispatcher.

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

Register a creating model event with the dispatcher.

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

Register a created model event with the dispatcher.

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

Register a deleting model event with the dispatcher.

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

Register a deleted model event with the dispatcher.

from Model
static void flushEventListeners()

Remove all of the event listeners for the model.

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

Register a model event with the dispatcher.

from Model
array getObservableEvents()

Get the observable event names.

from Model
void setObservableEvents(array $observables)

Set the observable event names.

from Model
void addObservableEvents(mixed $observables)

Add an observable event name.

from Model
void removeObservableEvents(mixed $observables)

Remove an observable event name.

from Model
int increment(string $column, int $amount = 1)

Increment a column's value by a given amount.

from Model
int decrement(string $column, int $amount = 1)

Decrement a column's value by a given amount.

from Model
int incrementOrDecrement(string $column, int $amount, string $method)

Run the increment or decrement method on the model.

from Model
void incrementOrDecrementAttributeValue(string $column, int $amount, string $method)

Increment the underlying attribute value and sync with original.

from Model
bool|int update(array $attributes = array())

Update the model in the database.

from Model
bool push()

Save the model and all of its relationships.

from Model
bool save(array $options = array())

Save the model to the database.

from Model
void finishSave(array $options)

Finish processing on a successful save operation.

from Model
bool|null performUpdate(Builder $query, array $options = [])

Perform a model update operation.

from Model
bool performInsert(Builder $query, array $options = [])

Perform a model insert operation.

from Model
void insertAndSetId(Builder $query, array $attributes)

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

from Model
void touchOwners()

Touch the owning relations of the model.

from Model
bool touches(string $relation)

Determine if the model touches a given relation.

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

Fire the given event for the model.

from Model
Builder setKeysForSaveQuery(Builder $query)

Set the keys for a save update query.

mixed getKeyForSaveQuery()

Get the primary key value for a save query.

from Model
bool touch()

Update the model's update timestamp.

from Model
void updateTimestamps()

Update the creation and update timestamps.

from Model
void setCreatedAt(mixed $value)

Set the value of the "created at" attribute.

from Model
void setUpdatedAt(mixed $value)

Set the value of the "updated at" attribute.

from Model
string getCreatedAtColumn()

Get the name of the "created at" column.

string getUpdatedAtColumn()

Get the name of the "updated at" column.

Carbon freshTimestamp()

Get a fresh timestamp for the model.

from Model
string freshTimestampString()

Get a fresh timestamp for the model.

from Model
Builder newQuery()

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

from Model
Builder newQueryWithoutScope(ScopeInterface $scope)

Get a new query instance without a given scope.

from Model
Builder|Model newQueryWithoutScopes()

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

from Model
Builder applyGlobalScopes(Builder $builder)

Apply all of the global scopes to an Eloquent builder.

from Model
Builder removeGlobalScopes(Builder $builder)

Remove all of the global scopes from an Eloquent builder.

from Model
Builder|Model newEloquentBuilder(Builder $query)

Create a new Eloquent query builder for the model.

from Model
Builder newBaseQueryBuilder()

Get a new query builder instance for the connection.

from Model
Collection newCollection(array $models = array())

Create a new Eloquent Collection instance.

from Model
Pivot newPivot(Model $parent, array $attributes, string $table, bool $exists)

Create a new pivot model instance.

from Model
string getTable()

Get the table associated with the model.

from Model
void setTable(string $table)

Set the table associated with the model.

from Model
mixed getKey()

Get the value of the model's primary key.

from Model
string getKeyName()

Get the primary key for the model.

from Model
void setKeyName(string $key)

Set the primary key for the model.

from Model
string getQualifiedKeyName()

Get the table qualified key name.

from Model
bool usesTimestamps()

Determine if the model uses timestamps.

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

Get the polymorphic relationship columns.

from Model
string getMorphClass()

Get the class name for polymorphic relations.

from Model
int getPerPage()

Get the number of models to return per page.

from Model
void setPerPage(int $perPage)

Set the number of models to return per page.

from Model
string getForeignKey()

Get the foreign key column name.

array getHidden()

Get the hidden attributes for the model.

from Model
void setHidden(array $hidden)

Set the hidden attributes for the model.

from Model
void setVisible(array $visible)

Set the visible attributes for the model.

from Model
void setAppends(array $appends)

Set the accessors to append to model arrays.

from Model
array getFillable()

Get the fillable attributes for the model.

from Model
$this fillable(array $fillable)

Set the fillable attributes for the model.

from Model
array getGuarded()

get the guarded attributes for the model.

from Model
$this guard(array $guarded)

Set the guarded attributes for the model.

from Model
static void unguard()

Disable all mass assignable restrictions.

from Model
static void reguard()

Enable the mass assignment restrictions.

from Model
static void setUnguardState(bool $state)

Set "unguard" to a given state.

from Model
bool isFillable(string $key)

Determine if the given attribute may be mass assigned.

from Model
bool isGuarded(string $key)

Determine if the given key is guarded.

from Model
bool totallyGuarded()

Determine if the model is totally guarded.

from Model
string removeTableFromKey(string $key)

Remove the table name from a given key.

from Model
array getTouchedRelations()

Get the relationships that are touched on save.

from Model
void setTouchedRelations(array $touches)

Set the relationships that are touched on save.

from Model
bool getIncrementing()

Get the value indicating whether the IDs are incrementing.

from Model
void setIncrementing(bool $value)

Set whether IDs are incrementing.

from Model
string toJson(int $options)

Convert the model instance to JSON.

from Model
array jsonSerialize()

Convert the object into something JSON serializable.

from Model
array toArray()

Convert the model instance to an array.

from Model
array attributesToArray()

Convert the model's attributes to an array.

from Model
array getArrayableAttributes()

Get an attribute array of all arrayable attributes.

from Model
array getArrayableAppends()

Get all of the appendable values that are arrayable.

from Model
array relationsToArray()

Get the model's relationships in array form.

from Model
array getArrayableRelations()

Get an attribute array of all arrayable relations.

from Model
array getArrayableItems(array $values)

Get an attribute array of all arrayable values.

from Model
mixed getAttribute(string $key)

Get an attribute from the model.

from Model
mixed getAttributeValue(string $key)

Get a plain attribute (not a relationship).

from Model
mixed getAttributeFromArray(string $key)

Get an attribute from the $attributes array.

from Model
mixed getRelationshipFromMethod(string $key, string $camelKey)

Get a relationship value from a method.

from Model
bool hasGetMutator(string $key)

Determine if a get mutator exists for an attribute.

from Model
mixed mutateAttribute(string $key, mixed $value)

Get the value of an attribute using its mutator.

from Model
mixed mutateAttributeForArray(string $key, mixed $value)

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

from Model
void setAttribute(string $key, mixed $value)

Set a given attribute on the model.

from Model
bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

from Model
array getDates()

Get the attributes that should be converted to dates.

from Model
string fromDateTime(DateTime|int $value)

Convert a DateTime to a storable string.

from Model
Carbon asDateTime(mixed $value)

Return a timestamp as DateTime object.

from Model
string getDateFormat()

Get the format for database stored dates.

from Model
Model replicate(array $except = null)

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

from Model
array getAttributes()

Get all of the current attributes on the model.

from Model
void setRawAttributes(array $attributes, bool $sync = false)

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

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

Get the model's original attribute values.

from Model
$this syncOriginal()

Sync the original attributes with the current.

from Model
$this syncOriginalAttribute(string $attribute)

Sync a single original attribute with its current value.

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

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

from Model
array getDirty()

Get the attributes that have been changed since last sync.

from Model
bool originalIsNumericallyEquivalent(string $key)

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

from Model
array getRelations()

Get all the loaded relations for the instance.

from Model
mixed getRelation(string $relation)

Get a specified relationship.

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

Set the specific relationship in the model.

from Model
$this setRelations(array $relations)

Set the entire relations array on the model.

from Model
Connection getConnection()

Get the database connection for the model.

from Model
string getConnectionName()

Get the current connection name for the model.

from Model
$this setConnection(string $name)

Set the connection associated with the model.

from Model
static Connection resolveConnection(string $connection = null)

Resolve a connection instance.

from Model
static ConnectionResolverInterface getConnectionResolver()

Get the connection resolver instance.

from Model
static void setConnectionResolver(ConnectionResolverInterface $resolver)

Set the connection resolver instance.

from Model
static void unsetConnectionResolver()

Unset the connection resolver for models.

from Model
static Dispatcher getEventDispatcher()

Get the event dispatcher instance.

from Model
static void setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

from Model
static void unsetEventDispatcher()

Unset the event dispatcher for models.

from Model
array getMutatedAttributes()

Get the mutated attributes for a given instance.

from Model
mixed __get(string $key)

Dynamically retrieve attributes on the model.

from Model
void __set(string $key, mixed $value)

Dynamically set attributes on the model.

from Model
bool offsetExists(mixed $offset)

Determine if the given attribute exists.

from Model
mixed offsetGet(mixed $offset)

Get the value for a given offset.

from Model
void offsetSet(mixed $offset, mixed $value)

Set the value for a given offset.

from Model
void offsetUnset(mixed $offset)

Unset the value for a given offset.

from Model
bool __isset(string $key)

Determine if an attribute exists on the model.

from Model
void __unset(string $key)

Unset an attribute on the model.

from Model
mixed __call(string $method, array $parameters)

Handle dynamic method calls into the method.

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

Handle dynamic static method calls into the method.

from Model
string __toString()

Convert the model to its string representation.

from Model
void __wakeup()

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

from Model
Builder getDeleteQuery()

Get the query builder for a delete operation on the pivot.

string getOtherKey()

Get the "other key" column name.

$this setPivotKeys(string $foreignKey, string $otherKey)

Set the key names for the pivot model instance.

bool hasTimestampAttributes()

Determine if the pivot model has timestamp attributes.

Details

void __construct(Model $parent, array $attributes, string $table, bool $exists = false)

Create a new pivot model instance.

Parameters

Model $parent
array $attributes
string $table
bool $exists

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 addGlobalScope(ScopeInterface $scope)

Register a new global scope on the model.

Parameters

ScopeInterface $scope

Return Value

void

static bool hasGlobalScope(ScopeInterface $scope)

Determine if a model has a global scope.

Parameters

ScopeInterface $scope

Return Value

bool

static ScopeInterface|null getGlobalScope(ScopeInterface $scope)

Get a global scope registered with the model.

Parameters

ScopeInterface $scope

Return Value

ScopeInterface|null

ScopeInterface[] getGlobalScopes()

Get the global scopes for this class instance.

Return Value

ScopeInterface[]

static void observe(object $class)

Register an observer with the Model.

Parameters

object $class

Return Value

void

$this fill(array $attributes)

Fill the model with an array of attributes.

Parameters

array $attributes

Return Value

$this

Exceptions

MassAssignmentException

protected array fillableFromArray(array $attributes)

Get the fillable attributes of a given array.

Parameters

array $attributes

Return Value

array

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

Create a new instance of the given model.

Parameters

array $attributes
bool $exists

Return Value

Model

Model newFromBuilder(array $attributes = array())

Create a new model instance that is existing.

Parameters

array $attributes

Return Value

Model

static Collection hydrate(array $items, string $connection = null)

Create a collection of models from plain arrays.

Parameters

array $items
string $connection

Return Value

Collection

static Collection hydrateRaw(string $query, array $bindings = array(), string $connection = null)

Create a collection of models from a raw query.

Parameters

string $query
array $bindings
string $connection

Return Value

Collection

static Model create(array $attributes)

Save a new model and return the instance.

Parameters

array $attributes

Return Value

Model

static Model firstOrCreate(array $attributes)

Get the first record matching the attributes or create it.

Parameters

array $attributes

Return Value

Model

static Model firstOrNew(array $attributes)

Get the first record matching the attributes or instantiate it.

Parameters

array $attributes

Return Value

Model

static Model updateOrCreate(array $attributes, array $values = array())

Create or update a record matching the attributes, and fill it with values.

Parameters

array $attributes
array $values

Return Value

Model

static protected Model|null firstByAttributes(array $attributes)

Get the first model for the given attributes.

Parameters

array $attributes

Return Value

Model|null

static Builder query()

Begin querying the model.

Return Value

Builder

static Builder on(string $connection = null)

Begin querying the model on a given connection.

Parameters

string $connection

Return Value

Builder

static Builder onWriteConnection()

Begin querying the model on the write connection.

Return Value

Builder

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

Get all of the models from the database.

Parameters

array $columns

Return Value

Collection|Model[]

static Collection|Model|null find(mixed $id, array $columns = array('*'))

Find a model by its primary key.

Parameters

mixed $id
array $columns

Return Value

Collection|Model|null

static Collection|Model findOrNew(mixed $id, array $columns = array('*'))

Find a model by its primary key or return new static.

Parameters

mixed $id
array $columns

Return Value

Collection|Model

static Collection|Model findOrFail(mixed $id, array $columns = array('*'))

Find a model by its primary key or throw an exception.

Parameters

mixed $id
array $columns

Return Value

Collection|Model

Exceptions

ModelNotFoundException

$this load(array|string $relations)

Eager load relations on the model.

Parameters

array|string $relations

Return Value

$this

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

Being querying a model with eager loading.

Parameters

array|string $relations

Return Value

Builder|Model

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

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

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

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

Parameters

string $related
string $foreignKey
string $otherKey
string $relation

Return Value

BelongsTo

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

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

Parameters

string $name
string $type
string $id

Return Value

MorphTo

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

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

Define a has-many-through relationship.

Parameters

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

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

BelongsToMany belongsToMany(string $related, string $table = null, string $foreignKey = null, string $otherKey = null, string $relation = null)

Define a many-to-many relationship.

Parameters

string $related
string $table
string $foreignKey
string $otherKey
string $relation

Return Value

BelongsToMany

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.

Parameters

string $related
string $name
string $table
string $foreignKey
string $otherKey
bool $inverse

Return Value

MorphToMany

MorphToMany morphedByMany(string $related, string $name, string $table = null, string $foreignKey = null, string $otherKey = null)

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

Parameters

string $related
string $name
string $table
string $foreignKey
string $otherKey

Return Value

MorphToMany

protected string getBelongsToManyCaller()

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

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 pivot model record from the database.

Return Value

bool|null

void forceDelete()

Force a hard delete on a soft deleted model.

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

Return Value

void

protected void performDeleteOnModel()

Perform the actual delete query on this model instance.

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 protected void registerModelEvent(string $event, Closure|string $callback)

Register a model event with the dispatcher.

Parameters

string $event
Closure|string $callback

Return Value

void

array getObservableEvents()

Get the observable event names.

Return Value

array

void setObservableEvents(array $observables)

Set the observable event names.

Parameters

array $observables

Return Value

void

void addObservableEvents(mixed $observables)

Add an observable event name.

Parameters

mixed $observables

Return Value

void

void removeObservableEvents(mixed $observables)

Remove an observable event name.

Parameters

mixed $observables

Return Value

void

protected int increment(string $column, int $amount = 1)

Increment a column's value by a given amount.

Parameters

string $column
int $amount

Return Value

int

protected int decrement(string $column, int $amount = 1)

Decrement a column's value by a given amount.

Parameters

string $column
int $amount

Return Value

int

protected int incrementOrDecrement(string $column, int $amount, string $method)

Run the increment or decrement method on the model.

Parameters

string $column
int $amount
string $method

Return Value

int

protected void incrementOrDecrementAttributeValue(string $column, int $amount, string $method)

Increment the underlying attribute value and sync with original.

Parameters

string $column
int $amount
string $method

Return Value

void

bool|int update(array $attributes = array())

Update the model in the database.

Parameters

array $attributes

Return Value

bool|int

bool push()

Save the model and all of its relationships.

Return Value

bool

bool save(array $options = array())

Save the model to the database.

Parameters

array $options

Return Value

bool

protected void finishSave(array $options)

Finish processing on a successful save operation.

Parameters

array $options

Return Value

void

protected bool|null performUpdate(Builder $query, array $options = [])

Perform a model update operation.

Parameters

Builder $query
array $options

Return Value

bool|null

protected bool performInsert(Builder $query, array $options = [])

Perform a model insert operation.

Parameters

Builder $query
array $options

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

void touchOwners()

Touch the owning relations of the model.

Return Value

void

bool touches(string $relation)

Determine if the model touches a given relation.

Parameters

string $relation

Return Value

bool

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

Fire the given event for the model.

Parameters

string $event
bool $halt

Return Value

mixed

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

bool touch()

Update the model's update timestamp.

Return Value

bool

protected void updateTimestamps()

Update the creation and update timestamps.

Return Value

void

void setCreatedAt(mixed $value)

Set the value of the "created at" attribute.

Parameters

mixed $value

Return Value

void

void setUpdatedAt(mixed $value)

Set the value of the "updated at" attribute.

Parameters

mixed $value

Return Value

void

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

Carbon freshTimestamp()

Get a fresh timestamp for the model.

Return Value

Carbon

string freshTimestampString()

Get a fresh timestamp for the model.

Return Value

string

Builder newQuery()

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

Return Value

Builder

Builder newQueryWithoutScope(ScopeInterface $scope)

Get a new query instance without a given scope.

Parameters

ScopeInterface $scope

Return Value

Builder

Builder|Model newQueryWithoutScopes()

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

Return Value

Builder|Model

Builder applyGlobalScopes(Builder $builder)

Apply all of the global scopes to an Eloquent builder.

Parameters

Builder $builder

Return Value

Builder

Builder removeGlobalScopes(Builder $builder)

Remove all of the global scopes from an Eloquent builder.

Parameters

Builder $builder

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 = array())

Create a new Eloquent Collection instance.

Parameters

array $models

Return Value

Collection

Pivot newPivot(Model $parent, array $attributes, string $table, bool $exists)

Create a new pivot model instance.

Parameters

Model $parent
array $attributes
string $table
bool $exists

Return Value

Pivot

string getTable()

Get the table associated with the model.

Return Value

string

void setTable(string $table)

Set the table associated with the model.

Parameters

string $table

Return Value

void

mixed getKey()

Get the value of the model's primary key.

Return Value

mixed

string getKeyName()

Get the primary key for the model.

Return Value

string

void setKeyName(string $key)

Set the primary key for the model.

Parameters

string $key

Return Value

void

string getQualifiedKeyName()

Get the table qualified key name.

Return Value

string

bool usesTimestamps()

Determine if the model uses timestamps.

Return Value

bool

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

int getPerPage()

Get the number of models to return per page.

Return Value

int

void setPerPage(int $perPage)

Set the number of models to return per page.

Parameters

int $perPage

Return Value

void

string getForeignKey()

Get the foreign key column name.

Return Value

string

array getHidden()

Get the hidden attributes for the model.

Return Value

array

void setHidden(array $hidden)

Set the hidden attributes for the model.

Parameters

array $hidden

Return Value

void

void setVisible(array $visible)

Set the visible attributes for the model.

Parameters

array $visible

Return Value

void

void setAppends(array $appends)

Set the accessors to append to model arrays.

Parameters

array $appends

Return Value

void

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()

Disable all mass assignable restrictions.

Return Value

void

static void reguard()

Enable the mass assignment restrictions.

Return Value

void

static void setUnguardState(bool $state)

Set "unguard" to a given state.

Parameters

bool $state

Return Value

void

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 string removeTableFromKey(string $key)

Remove the table name from a given key.

Parameters

string $key

Return Value

string

array getTouchedRelations()

Get the relationships that are touched on save.

Return Value

array

void setTouchedRelations(array $touches)

Set the relationships that are touched on save.

Parameters

array $touches

Return Value

void

bool getIncrementing()

Get the value indicating whether the IDs are incrementing.

Return Value

bool

void setIncrementing(bool $value)

Set whether IDs are incrementing.

Parameters

bool $value

Return Value

void

string toJson(int $options)

Convert the model instance to JSON.

Parameters

int $options

Return Value

string

array jsonSerialize()

Convert the object into something JSON serializable.

Return Value

array

array toArray()

Convert the model instance to an array.

Return Value

array

array attributesToArray()

Convert the model's attributes to an array.

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

protected 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

protected mixed getRelationshipFromMethod(string $key, string $camelKey)

Get a relationship value from a method.

Parameters

string $key
string $camelKey

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

void setAttribute(string $key, mixed $value)

Set a given attribute on the model.

Parameters

string $key
mixed $value

Return Value

void

bool hasSetMutator(string $key)

Determine if a set mutator exists for an attribute.

Parameters

string $key

Return Value

bool

array getDates()

Get the attributes that should be converted to dates.

Return Value

array

string fromDateTime(DateTime|int $value)

Convert a DateTime to a storable string.

Parameters

DateTime|int $value

Return Value

string

protected Carbon asDateTime(mixed $value)

Return a timestamp as DateTime object.

Parameters

mixed $value

Return Value

Carbon

protected string getDateFormat()

Get the format for database stored dates.

Return Value

string

Model replicate(array $except = null)

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

Parameters

array $except

Return Value

Model

array getAttributes()

Get all of the current attributes on the model.

Return Value

array

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

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

Parameters

array $attributes
bool $sync

Return Value

void

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

Get the model's original attribute values.

Parameters

string $key
mixed $default

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

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

array getDirty()

Get the attributes that have been changed since last sync.

Return Value

array

protected bool originalIsNumericallyEquivalent(string $key)

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

Parameters

string $key

Return Value

bool

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

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

Set the specific relationship in the model.

Parameters

string $relation
mixed $value

Return Value

$this

$this setRelations(array $relations)

Set the entire relations array on the model.

Parameters

array $relations

Return Value

$this

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 $connection = null)

Resolve a connection instance.

Parameters

string $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

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

array getMutatedAttributes()

Get the mutated attributes for a given instance.

Return Value

array

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 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 method.

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

protected Builder getDeleteQuery()

Get the query builder for a delete operation on the pivot.

Return Value

Builder

string getOtherKey()

Get the "other key" column name.

Return Value

string

$this setPivotKeys(string $foreignKey, string $otherKey)

Set the key names for the pivot model instance.

Parameters

string $foreignKey
string $otherKey

Return Value

$this

bool hasTimestampAttributes()

Determine if the pivot model has timestamp attributes.

Return Value

bool

© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/4.2/Illuminate/Database/Eloquent/Relations/Pivot.html