MorphPivot
class MorphPivot extends Pivot (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 |
$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. |
from Pivot |
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 value of the polymorphic relation. |
|
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. |
from Pivot |
protected string | $foreignKey | The name of the foreign key column. |
from Pivot |
protected string | $otherKey | The name of the "other key" column. |
from Pivot |
protected string | $morphType | The type of the polymorphic relation. |
Methods
Create a new pivot model instance.
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.
Get the first record matching the attributes or create it.
Get the first record matching the attributes or instantiate it.
Create or update a record matching the attributes, and fill it with values.
Get the first model for the given attributes.
Begin querying the model on a given connection.
Get all of the models from the database.
Find a model by its primary key.
Find a model by its primary key or return new static.
Find a model by its primary key or throw an exception.
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 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.
Delete the pivot model record from the database.
Register a model event with the dispatcher.
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.
Insert the given attributes and set the ID on the model.
Fire the given event for the model.
Get a new query builder that doesn't have any global scopes.
Create a new Eloquent Collection instance.
Create a new pivot model instance.
Get the polymorphic relationship columns.
Get a relationship value from a method.
Get the value of an attribute using its mutator.
Get the value of an attribute using its mutator for array conversion.
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 new and old values for a given key are numerically equivalent.
Set the specific relationship in the model.
Resolve a connection instance.
Get the connection resolver instance.
Handle dynamic method calls into the method.
Handle dynamic static method calls into the method.
Set the key names for the pivot model instance.
Set the morph type for the pivot.
Set the morph class for the pivot.
Details
in
Pivot at line 45
void
__construct(Model $parent, array $attributes, string $table, bool $exists = false)
Create a new pivot model instance.
in
Model at line 257
protected void
bootIfNotBooted()
Check if the model needs to be booted and if so, do it.
in
Model at line 278
static protected void
boot()
The "booting" method of the model.
in
Model at line 305
static protected void
bootTraits()
Boot all of the bootable traits on the model.
in
Model at line 322
static void
addGlobalScope(ScopeInterface $scope)
Register a new global scope on the model.
in
Model at line 333
static bool
hasGlobalScope(ScopeInterface $scope)
Determine if a model has a global scope.
in
Model at line 344
static ScopeInterface|null
getGlobalScope(ScopeInterface $scope)
Get a global scope registered with the model.
in
Model at line 357
ScopeInterface[]
getGlobalScopes()
Get the global scopes for this class instance.
in
Model at line 368
static void
observe(object $class)
Register an observer with the Model.
in
Model at line 394
$this
fill(array $attributes)
Fill the model with an array of attributes.
in
Model at line 424
protected array
fillableFromArray(array $attributes)
Get the fillable attributes of a given array.
in
Model at line 441
Model
newInstance(array $attributes = array(), bool $exists = false)
Create a new instance of the given model.
in
Model at line 459
Model
newFromBuilder(array $attributes = array())
Create a new model instance that is existing.
in
Model at line 475
static Collection
hydrate(array $items, string $connection = null)
Create a collection of models from plain arrays.
in
Model at line 502
static Collection
hydrateRaw(string $query, array $bindings = array(), string $connection = null)
Create a collection of models from a raw query.
in
Model at line 522
static Model
create(array $attributes)
Save a new model and return the instance.
in
Model at line 537
static Model
firstOrCreate(array $attributes)
Get the first record matching the attributes or create it.
in
Model at line 553
static Model
firstOrNew(array $attributes)
Get the first record matching the attributes or instantiate it.
in
Model at line 570
static Model
updateOrCreate(array $attributes, array $values = array())
Create or update a record matching the attributes, and fill it with values.
in
Model at line 585
static protected Model|null
firstByAttributes(array $attributes)
Get the first model for the given attributes.
in
Model at line 595
static Builder
query()
Begin querying the model.
in
Model at line 606
static Builder
on(string $connection = null)
Begin querying the model on a given connection.
in
Model at line 623
static Builder
onWriteConnection()
Begin querying the model on the write connection.
in
Model at line 636
static Collection|Model[]
all(array $columns = array('*'))
Get all of the models from the database.
in
Model at line 650
static Collection|Model|null
find(mixed $id, array $columns = array('*'))
Find a model by its primary key.
in
Model at line 666
static Collection|Model
findOrNew(mixed $id, array $columns = array('*'))
Find a model by its primary key or return new static.
in
Model at line 682
static Collection|Model
findOrFail(mixed $id, array $columns = array('*'))
Find a model by its primary key or throw an exception.
in
Model at line 695
$this
load(array|string $relations)
Eager load relations on the model.
in
Model at line 712
static Builder|Model
with(array|string $relations)
Being querying a model with eager loading.
in
Model at line 729
HasOne
hasOne(string $related, string $foreignKey = null, string $localKey = null)
Define a one-to-one relationship.
in
Model at line 750
MorphOne
morphOne(string $related, string $name, string $type = null, string $id = null, string $localKey = null)
Define a polymorphic one-to-one relationship.
in
Model at line 772
BelongsTo
belongsTo(string $related, string $foreignKey = null, string $otherKey = null, string $relation = null)
Define an inverse one-to-one or many relationship.
in
Model at line 812
MorphTo
morphTo(string $name = null, string $type = null, string $id = null)
Define a polymorphic, inverse one-to-one or many relationship.
in
Model at line 857
HasMany
hasMany(string $related, string $foreignKey = null, string $localKey = null)
Define a one-to-many relationship.
in
Model at line 877
HasManyThrough
hasManyThrough(string $related, string $through, string|null $firstKey = null, string|null $secondKey = null)
Define a has-many-through relationship.
in
Model at line 898
MorphMany
morphMany(string $related, string $name, string $type = null, string $id = null, string $localKey = null)
Define a polymorphic one-to-many relationship.
in
Model at line 924
BelongsToMany
belongsToMany(string $related, string $table = null, string $foreignKey = null, string $otherKey = null, string $relation = null)
Define a many-to-many relationship.
in
Model at line 970
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.
MorphToMany
morphedByMany(string $related, string $name, string $table = null, string $foreignKey = null, string $otherKey = null)
Define a polymorphic, inverse many-to-many relationship.
protected string
getBelongsToManyCaller()
Get the relationship name of the belongs to many.
string
joiningTable(string $related)
Get the joining table name for a many-to-many relation.
static int
destroy(array|int $ids)
Destroy the models for the given IDs.
bool|null
delete()
Delete the pivot model record from the database.
void
forceDelete()
Force a hard delete on a soft deleted model.
This method protects developers from running forceDelete when trait is missing.
protected void
performDeleteOnModel()
Perform the actual delete query on this model instance.
static void
saving(Closure|string $callback)
Register a saving model event with the dispatcher.
static void
saved(Closure|string $callback)
Register a saved model event with the dispatcher.
static void
updating(Closure|string $callback)
Register an updating model event with the dispatcher.
static void
updated(Closure|string $callback)
Register an updated model event with the dispatcher.
static void
creating(Closure|string $callback)
Register a creating model event with the dispatcher.
static void
created(Closure|string $callback)
Register a created model event with the dispatcher.
static void
deleting(Closure|string $callback)
Register a deleting model event with the dispatcher.
static void
deleted(Closure|string $callback)
Register a deleted model event with the dispatcher.
static void
flushEventListeners()
Remove all of the event listeners for the model.
static protected void
registerModelEvent(string $event, Closure|string $callback)
Register a model event with the dispatcher.
array
getObservableEvents()
Get the observable event names.
void
setObservableEvents(array $observables)
Set the observable event names.
void
addObservableEvents(mixed $observables)
Add an observable event name.
void
removeObservableEvents(mixed $observables)
Remove an observable event name.
protected int
increment(string $column, int $amount = 1)
Increment a column's value by a given amount.
protected int
decrement(string $column, int $amount = 1)
Decrement a column's value by a given amount.
protected int
incrementOrDecrement(string $column, int $amount, string $method)
Run the increment or decrement method on the model.
protected void
incrementOrDecrementAttributeValue(string $column, int $amount, string $method)
Increment the underlying attribute value and sync with original.
bool|int
update(array $attributes = array())
Update the model in the database.
bool
push()
Save the model and all of its relationships.
bool
save(array $options = array())
Save the model to the database.
protected void
finishSave(array $options)
Finish processing on a successful save operation.
protected bool|null
performUpdate(Builder $query, array $options = [])
Perform a model update operation.
protected bool
performInsert(Builder $query, array $options = [])
Perform a model insert operation.
protected void
insertAndSetId(Builder $query, array $attributes)
Insert the given attributes and set the ID on the model.
void
touchOwners()
Touch the owning relations of the model.
bool
touches(string $relation)
Determine if the model touches a given relation.
protected mixed
fireModelEvent(string $event, bool $halt = true)
Fire the given event for the model.
protected mixed
getKeyForSaveQuery()
Get the primary key value for a save query.
bool
touch()
Update the model's update timestamp.
protected void
updateTimestamps()
Update the creation and update timestamps.
void
setCreatedAt(mixed $value)
Set the value of the "created at" attribute.
void
setUpdatedAt(mixed $value)
Set the value of the "updated at" attribute.
in
Pivot at line 156
string
getCreatedAtColumn()
Get the name of the "created at" column.
in
Pivot at line 166
string
getUpdatedAtColumn()
Get the name of the "updated at" column.
Carbon
freshTimestamp()
Get a fresh timestamp for the model.
string
freshTimestampString()
Get a fresh timestamp for the model.
Builder
newQuery()
Get a new query builder for the model's table.
Builder
newQueryWithoutScope(ScopeInterface $scope)
Get a new query instance without a given scope.
Builder
removeGlobalScopes(Builder $builder)
Remove all of the global scopes from an Eloquent builder.
protected Builder
newBaseQueryBuilder()
Get a new query builder instance for the connection.
Collection
newCollection(array $models = array())
Create a new Eloquent Collection instance.
Pivot
newPivot(Model $parent, array $attributes, string $table, bool $exists)
Create a new pivot model instance.
string
getTable()
Get the table associated with the model.
void
setTable(string $table)
Set the table associated with the model.
mixed
getKey()
Get the value of the model's primary key.
string
getKeyName()
Get the primary key for the model.
void
setKeyName(string $key)
Set the primary key for the model.
string
getQualifiedKeyName()
Get the table qualified key name.
bool
usesTimestamps()
Determine if the model uses timestamps.
protected array
getMorphs(string $name, string $type, string $id)
Get the polymorphic relationship columns.
string
getMorphClass()
Get the class name for polymorphic relations.
int
getPerPage()
Get the number of models to return per page.
void
setPerPage(int $perPage)
Set the number of models to return per page.
in
Pivot at line 110
string
getForeignKey()
Get the foreign key column name.
array
getHidden()
Get the hidden attributes for the model.
void
setHidden(array $hidden)
Set the hidden attributes for the model.
void
setVisible(array $visible)
Set the visible attributes for the model.
void
setAppends(array $appends)
Set the accessors to append to model arrays.
array
getFillable()
Get the fillable attributes for the model.
$this
fillable(array $fillable)
Set the fillable attributes for the model.
array
getGuarded()
get the guarded attributes for the model.
$this
guard(array $guarded)
Set the guarded attributes for the model.
static void
unguard()
Disable all mass assignable restrictions.
static void
reguard()
Enable the mass assignment restrictions.
static void
setUnguardState(bool $state)
Set "unguard" to a given state.
bool
isFillable(string $key)
Determine if the given attribute may be mass assigned.
bool
isGuarded(string $key)
Determine if the given key is guarded.
bool
totallyGuarded()
Determine if the model is totally guarded.
protected string
removeTableFromKey(string $key)
Remove the table name from a given key.
array
getTouchedRelations()
Get the relationships that are touched on save.
void
setTouchedRelations(array $touches)
Set the relationships that are touched on save.
bool
getIncrementing()
Get the value indicating whether the IDs are incrementing.
void
setIncrementing(bool $value)
Set whether IDs are incrementing.
string
toJson(int $options = 0)
Convert the object to its JSON representation.
array
jsonSerialize()
Convert the object into something JSON serializable.
array
toArray()
Get the instance as an array.
array
attributesToArray()
Convert the model's attributes to an array.
protected array
getArrayableAttributes()
Get an attribute array of all arrayable attributes.
protected array
getArrayableAppends()
Get all of the appendable values that are arrayable.
array
relationsToArray()
Get the model's relationships in array form.
protected array
getArrayableRelations()
Get an attribute array of all arrayable relations.
protected array
getArrayableItems(array $values)
Get an attribute array of all arrayable values.
mixed
getAttribute(string $key)
Get an attribute from the model.
protected mixed
getAttributeValue(string $key)
Get a plain attribute (not a relationship).
protected mixed
getAttributeFromArray(string $key)
Get an attribute from the $attributes array.
protected mixed
getRelationshipFromMethod(string $key, string $camelKey)
Get a relationship value from a method.
bool
hasGetMutator(string $key)
Determine if a get mutator exists for an attribute.
protected mixed
mutateAttribute(string $key, mixed $value)
Get the value of an attribute using its mutator.
protected mixed
mutateAttributeForArray(string $key, mixed $value)
Get the value of an attribute using its mutator for array conversion.
void
setAttribute(string $key, mixed $value)
Set a given attribute on the model.
bool
hasSetMutator(string $key)
Determine if a set mutator exists for an attribute.
array
getDates()
Get the attributes that should be converted to dates.
string
fromDateTime(DateTime|int $value)
Convert a DateTime to a storable string.
protected Carbon
asDateTime(mixed $value)
Return a timestamp as DateTime object.
protected string
getDateFormat()
Get the format for database stored dates.
Model
replicate(array $except = null)
Clone the model into a new, non-existing instance.
array
getAttributes()
Get all of the current attributes on the model.
void
setRawAttributes(array $attributes, bool $sync = false)
Set the array of model attributes. No checking is done.
array
getOriginal(string $key = null, mixed $default = null)
Get the model's original attribute values.
$this
syncOriginal()
Sync the original attributes with the current.
$this
syncOriginalAttribute(string $attribute)
Sync a single original attribute with its current value.
bool
isDirty(array|string|null $attributes = null)
Determine if the model or given attribute(s) have been modified.
array
getDirty()
Get the attributes that have been changed since last sync.
protected bool
originalIsNumericallyEquivalent(string $key)
Determine if the new and old values for a given key are numerically equivalent.
array
getRelations()
Get all the loaded relations for the instance.
mixed
getRelation(string $relation)
Get a specified relationship.
$this
setRelation(string $relation, mixed $value)
Set the specific relationship in the model.
$this
setRelations(array $relations)
Set the entire relations array on the model.
Connection
getConnection()
Get the database connection for the model.
string
getConnectionName()
Get the current connection name for the model.
$this
setConnection(string $name)
Set the connection associated with the model.
static Connection
resolveConnection(string $connection = null)
Resolve a connection instance.
static ConnectionResolverInterface
getConnectionResolver()
Get the connection resolver instance.
static void
setConnectionResolver(ConnectionResolverInterface $resolver)
Set the connection resolver instance.
static void
unsetConnectionResolver()
Unset the connection resolver for models.
static Dispatcher
getEventDispatcher()
Get the event dispatcher instance.
static void
setEventDispatcher(Dispatcher $dispatcher)
Set the event dispatcher instance.
static void
unsetEventDispatcher()
Unset the event dispatcher for models.
array
getMutatedAttributes()
Get the mutated attributes for a given instance.
mixed
__get(string $key)
Dynamically retrieve attributes on the model.
void
__set(string $key, mixed $value)
Dynamically set attributes on the model.
bool
offsetExists(mixed $offset)
Determine if the given attribute exists.
mixed
offsetGet(mixed $offset)
Get the value for a given offset.
void
offsetSet(mixed $offset, mixed $value)
Set the value for a given offset.
void
offsetUnset(mixed $offset)
Unset the value for a given offset.
bool
__isset(string $key)
Determine if an attribute exists on the model.
void
__unset(string $key)
Unset an attribute on the model.
mixed
__call(string $method, array $parameters)
Handle dynamic method calls into the method.
static mixed
__callStatic(string $method, array $parameters)
Handle dynamic static method calls into the method.
string
__toString()
Convert the model to its string representation.
void
__wakeup()
When a model is being unserialized, check if it needs to be booted.
in
Pivot at line 96
protected Builder
getDeleteQuery()
Get the query builder for a delete operation on the pivot.
in
Pivot at line 120
string
getOtherKey()
Get the "other key" column name.
in
Pivot at line 132
$this
setPivotKeys(string $foreignKey, string $otherKey)
Set the key names for the pivot model instance.
in
Pivot at line 146
bool
hasTimestampAttributes()
Determine if the pivot model has timestamp attributes.
$this
setMorphType(string $morphType)
Set the morph type for the pivot.
MorphPivot
setMorphClass(string $morphClass)
Set the morph class for the pivot.