code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function loadSum($relations, $column) { return $this->loadAggregate($relations, $column, 'sum'); }
Eager load relation's column summations on the model. @param array|string $relations @param string $column @return $this
loadSum
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadAvg($relations, $column) { return $this->loadAggregate($relations, $column, 'avg'); }
Eager load relation average column values on the model. @param array|string $relations @param string $column @return $this
loadAvg
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadExists($relations) { return $this->loadAggregate($relations, '*', 'exists'); }
Eager load related model existence values on the model. @param array|string $relations @return $this
loadExists
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMorphAggregate($relation, $relations, $column, $function = null) { if (! $this->{$relation}) { return $this; } $className = get_class($this->{$relation}); $this->{$relation}->loadAggregate($relations[$className] ?? [], $column, $function); return $this; }
Eager load relationship column aggregation on the polymorphic relation of a model. @param string $relation @param array $relations @param string $column @param string|null $function @return $this
loadMorphAggregate
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMorphCount($relation, $relations) { return $this->loadMorphAggregate($relation, $relations, '*', 'count'); }
Eager load relationship counts on the polymorphic relation of a model. @param string $relation @param array $relations @return $this
loadMorphCount
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMorphMax($relation, $relations, $column) { return $this->loadMorphAggregate($relation, $relations, $column, 'max'); }
Eager load relationship max column values on the polymorphic relation of a model. @param string $relation @param array $relations @param string $column @return $this
loadMorphMax
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMorphMin($relation, $relations, $column) { return $this->loadMorphAggregate($relation, $relations, $column, 'min'); }
Eager load relationship min column values on the polymorphic relation of a model. @param string $relation @param array $relations @param string $column @return $this
loadMorphMin
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMorphSum($relation, $relations, $column) { return $this->loadMorphAggregate($relation, $relations, $column, 'sum'); }
Eager load relationship column summations on the polymorphic relation of a model. @param string $relation @param array $relations @param string $column @return $this
loadMorphSum
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMorphAvg($relation, $relations, $column) { return $this->loadMorphAggregate($relation, $relations, $column, 'avg'); }
Eager load relationship average column values on the polymorphic relation of a model. @param string $relation @param array $relations @param string $column @return $this
loadMorphAvg
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function increment($column, $amount = 1, array $extra = []) { return $this->incrementOrDecrement($column, $amount, $extra, 'increment'); }
Increment a column's value by a given amount. @param string $column @param float|int $amount @param array $extra @return int
increment
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function decrement($column, $amount = 1, array $extra = []) { return $this->incrementOrDecrement($column, $amount, $extra, 'decrement'); }
Decrement a column's value by a given amount. @param string $column @param float|int $amount @param array $extra @return int
decrement
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function incrementOrDecrement($column, $amount, $extra, $method) { if (! $this->exists) { return $this->newQueryWithoutRelationships()->{$method}($column, $amount, $extra); } $this->{$column} = $this->isClassDeviable($column) ? $this->deviateClassCastableAttribute($method, $column, $amount) : $this->{$column} + ($method === 'increment' ? $amount : $amount * -1); $this->forceFill($extra); if ($this->fireModelEvent('updating') === false) { return false; } if ($this->isClassDeviable($column)) { $amount = (clone $this)->setAttribute($column, $amount)->getAttributeFromArray($column); } return tap($this->setKeysForSaveQuery($this->newQueryWithoutScopes())->{$method}($column, $amount, $extra), function () use ($column) { $this->syncChanges(); $this->fireModelEvent('updated', false); $this->syncOriginalAttribute($column); }); }
Run the increment or decrement method on the model. @param string $column @param float|int $amount @param array $extra @param string $method @return int
incrementOrDecrement
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function update(array $attributes = [], array $options = []) { if (! $this->exists) { return false; } return $this->fill($attributes)->save($options); }
Update the model in the database. @param array<string, mixed> $attributes @param array<string, mixed> $options @return bool
update
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function updateOrFail(array $attributes = [], array $options = []) { if (! $this->exists) { return false; } return $this->fill($attributes)->saveOrFail($options); }
Update the model in the database within a transaction. @param array<string, mixed> $attributes @param array<string, mixed> $options @return bool @throws \Throwable
updateOrFail
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function updateQuietly(array $attributes = [], array $options = []) { if (! $this->exists) { return false; } return $this->fill($attributes)->saveQuietly($options); }
Update the model in the database without raising any events. @param array<string, mixed> $attributes @param array<string, mixed> $options @return bool
updateQuietly
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function incrementQuietly($column, $amount = 1, array $extra = []) { return static::withoutEvents( fn () => $this->incrementOrDecrement($column, $amount, $extra, 'increment') ); }
Increment a column's value by a given amount without raising any events. @param string $column @param float|int $amount @param array $extra @return int
incrementQuietly
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function decrementQuietly($column, $amount = 1, array $extra = []) { return static::withoutEvents( fn () => $this->incrementOrDecrement($column, $amount, $extra, 'decrement') ); }
Decrement a column's value by a given amount without raising any events. @param string $column @param float|int $amount @param array $extra @return int
decrementQuietly
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function push() { return $this->withoutRecursion(function () { if (! $this->save()) { return false; } // To sync all of the relationships to the database, we will simply spin through // the relationships and save each model via this "push" method, which allows // us to recurse into all of these nested relations for the model instance. foreach ($this->relations as $models) { $models = $models instanceof Collection ? $models->all() : [$models]; foreach (array_filter($models) as $model) { if (! $model->push()) { return false; } } } return true; }, true); }
Save the model and all of its relationships. @return bool
push
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function pushQuietly() { return static::withoutEvents(fn () => $this->push()); }
Save the model and all of its relationships without raising any events to the parent model. @return bool
pushQuietly
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function saveQuietly(array $options = []) { return static::withoutEvents(fn () => $this->save($options)); }
Save the model to the database without raising any events. @param array $options @return bool
saveQuietly
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function save(array $options = []) { $this->mergeAttributesFromCachedCasts(); $query = $this->newModelQuery(); // If the "saving" event returns false we'll bail out of the save and return // false, indicating that the save failed. This provides a chance for any // listeners to cancel save operations if validations fail or whatever. if ($this->fireModelEvent('saving') === false) { return false; } // If the model already exists in the database we can just update our record // that is already in this database using the current IDs in this "where" // clause to only update this model. Otherwise, we'll just insert them. if ($this->exists) { $saved = $this->isDirty() ? $this->performUpdate($query) : true; } // If the model is brand new, we'll insert it into our database and set the // ID attribute on the model to the value of the newly inserted row's ID // which is typically an auto-increment value managed by the database. else { $saved = $this->performInsert($query); if (! $this->getConnectionName() && $connection = $query->getConnection()) { $this->setConnection($connection->getName()); } } // If the model is successfully saved, we need to do a few more things once // that is done. We will call the "saved" method here to run any actions // we need to happen after a model gets successfully saved right here. if ($saved) { $this->finishSave($options); } return $saved; }
Save the model to the database. @param array $options @return bool
save
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function saveOrFail(array $options = []) { return $this->getConnection()->transaction(fn () => $this->save($options)); }
Save the model to the database within a transaction. @param array $options @return bool @throws \Throwable
saveOrFail
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function finishSave(array $options) { $this->fireModelEvent('saved', false); if ($this->isDirty() && ($options['touch'] ?? true)) { $this->touchOwners(); } $this->syncOriginal(); }
Perform any actions that are necessary after the model is saved. @param array $options @return void
finishSave
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function performUpdate(Builder $query) { // If the updating event returns false, we will cancel the update operation so // developers can hook Validation systems into their models and cancel this // operation if the model does not pass validation. Otherwise, we update. if ($this->fireModelEvent('updating') === false) { return false; } // First we need to create a fresh query instance and touch the creation and // update timestamp on the model which are maintained by us for developer // convenience. Then we will just continue saving the model instances. if ($this->usesTimestamps()) { $this->updateTimestamps(); } // Once we have run the update operation, we will fire the "updated" event for // this model instance. This will allow developers to hook into these after // models are updated, giving them a chance to do any special processing. $dirty = $this->getDirtyForUpdate(); if (count($dirty) > 0) { $this->setKeysForSaveQuery($query)->update($dirty); $this->syncChanges(); $this->fireModelEvent('updated', false); } return true; }
Perform a model update operation. @param \Illuminate\Database\Eloquent\Builder<static> $query @return bool
performUpdate
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function setKeysForSelectQuery($query) { $query->where($this->getKeyName(), '=', $this->getKeyForSelectQuery()); return $query; }
Set the keys for a select query. @param \Illuminate\Database\Eloquent\Builder<static> $query @return \Illuminate\Database\Eloquent\Builder<static>
setKeysForSelectQuery
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function getKeyForSelectQuery() { return $this->original[$this->getKeyName()] ?? $this->getKey(); }
Get the primary key value for a select query. @return mixed
getKeyForSelectQuery
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function setKeysForSaveQuery($query) { $query->where($this->getKeyName(), '=', $this->getKeyForSaveQuery()); return $query; }
Set the keys for a save update query. @param \Illuminate\Database\Eloquent\Builder<static> $query @return \Illuminate\Database\Eloquent\Builder<static>
setKeysForSaveQuery
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function getKeyForSaveQuery() { return $this->original[$this->getKeyName()] ?? $this->getKey(); }
Get the primary key value for a save query. @return mixed
getKeyForSaveQuery
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function performInsert(Builder $query) { if ($this->usesUniqueIds()) { $this->setUniqueIds(); } if ($this->fireModelEvent('creating') === false) { return false; } // First we'll need to create a fresh query instance and touch the creation and // update timestamps on this model, which are maintained by us for developer // convenience. After, we will just continue saving these model instances. if ($this->usesTimestamps()) { $this->updateTimestamps(); } // If the model has an incrementing key, we can use the "insertGetId" method on // the query builder, which will give us back the final inserted ID for this // table from the database. Not all tables have to be incrementing though. $attributes = $this->getAttributesForInsert(); if ($this->getIncrementing()) { $this->insertAndSetId($query, $attributes); } // If the table isn't incrementing we'll simply insert these attributes as they // are. These attribute arrays must contain an "id" column previously placed // there by the developer as the manually determined key for these models. else { if (empty($attributes)) { return true; } $query->insert($attributes); } // We will go ahead and set the exists property to true, so that it is set when // the created event is fired, just in case the developer tries to update it // during the event. This will allow them to do so and run an update here. $this->exists = true; $this->wasRecentlyCreated = true; $this->fireModelEvent('created', false); return true; }
Perform a model insert operation. @param \Illuminate\Database\Eloquent\Builder<static> $query @return bool
performInsert
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function insertAndSetId(Builder $query, $attributes) { $id = $query->insertGetId($attributes, $keyName = $this->getKeyName()); $this->setAttribute($keyName, $id); }
Insert the given attributes and set the ID on the model. @param \Illuminate\Database\Eloquent\Builder<static> $query @param array<string, mixed> $attributes @return void
insertAndSetId
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function destroy($ids) { if ($ids instanceof EloquentCollection) { $ids = $ids->modelKeys(); } if ($ids instanceof BaseCollection) { $ids = $ids->all(); } $ids = is_array($ids) ? $ids : func_get_args(); if (count($ids) === 0) { return 0; } // We will actually pull the models from the database table and call delete on // each of them individually so that their events get fired properly with a // correct set of attributes in case the developers wants to check these. $key = ($instance = new static)->getKeyName(); $count = 0; foreach ($instance->whereIn($key, $ids)->get() as $model) { if ($model->delete()) { $count++; } } return $count; }
Destroy the models for the given IDs. @param \Illuminate\Support\Collection|array|int|string $ids @return int
destroy
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function delete() { $this->mergeAttributesFromCachedCasts(); if (is_null($this->getKeyName())) { throw new LogicException('No primary key defined on model.'); } // If the model doesn't exist, there is nothing to delete so we'll just return // immediately and not do anything else. Otherwise, we will continue with a // deletion process on the model, firing the proper events, and so forth. if (! $this->exists) { return; } if ($this->fireModelEvent('deleting') === false) { return false; } // Here, we'll touch the owning models, verifying these timestamps get updated // for the models. This will allow any caching to get broken on the parents // by the timestamp. Then we will go ahead and delete the model instance. $this->touchOwners(); $this->performDeleteOnModel(); // Once the model has been deleted, we will fire off the deleted event so that // the developers may hook into post-delete operations. We will then return // a boolean true as the delete is presumably successful on the database. $this->fireModelEvent('deleted', false); return true; }
Delete the model from the database. @return bool|null @throws \LogicException
delete
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function deleteQuietly() { return static::withoutEvents(fn () => $this->delete()); }
Delete the model from the database without raising any events. @return bool
deleteQuietly
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function deleteOrFail() { if (! $this->exists) { return false; } return $this->getConnection()->transaction(fn () => $this->delete()); }
Delete the model from the database within a transaction. @return bool|null @throws \Throwable
deleteOrFail
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function forceDelete() { return $this->delete(); }
Force a hard delete on a soft deleted model. This method protects developers from running forceDelete when the trait is missing. @return bool|null
forceDelete
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function forceDestroy($ids) { return static::destroy($ids); }
Force a hard destroy on a soft deleted model. This method protects developers from running forceDestroy when the trait is missing. @param \Illuminate\Support\Collection|array|int|string $ids @return bool|null
forceDestroy
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function performDeleteOnModel() { $this->setKeysForSaveQuery($this->newModelQuery())->delete(); $this->exists = false; }
Perform the actual delete query on this model instance. @return void
performDeleteOnModel
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function query() { return (new static)->newQuery(); }
Begin querying the model. @return \Illuminate\Database\Eloquent\Builder<static>
query
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newQuery() { return $this->registerGlobalScopes($this->newQueryWithoutScopes()); }
Get a new query builder for the model's table. @return \Illuminate\Database\Eloquent\Builder<static>
newQuery
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newModelQuery() { return $this->newEloquentBuilder( $this->newBaseQueryBuilder() )->setModel($this); }
Get a new query builder that doesn't have any global scopes or eager loading. @return \Illuminate\Database\Eloquent\Builder<static>
newModelQuery
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newQueryWithoutRelationships() { return $this->registerGlobalScopes($this->newModelQuery()); }
Get a new query builder with no relationships loaded. @return \Illuminate\Database\Eloquent\Builder<static>
newQueryWithoutRelationships
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function registerGlobalScopes($builder) { foreach ($this->getGlobalScopes() as $identifier => $scope) { $builder->withGlobalScope($identifier, $scope); } return $builder; }
Register the global scopes for this builder instance. @param \Illuminate\Database\Eloquent\Builder<static> $builder @return \Illuminate\Database\Eloquent\Builder<static>
registerGlobalScopes
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newQueryWithoutScopes() { return $this->newModelQuery() ->with($this->with) ->withCount($this->withCount); }
Get a new query builder that doesn't have any global scopes. @return \Illuminate\Database\Eloquent\Builder<static>
newQueryWithoutScopes
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newQueryWithoutScope($scope) { return $this->newQuery()->withoutGlobalScope($scope); }
Get a new query instance without a given scope. @param \Illuminate\Database\Eloquent\Scope|string $scope @return \Illuminate\Database\Eloquent\Builder<static>
newQueryWithoutScope
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newQueryForRestoration($ids) { return $this->newQueryWithoutScopes()->whereKey($ids); }
Get a new query to restore one or more models by their queueable IDs. @param array|int $ids @return \Illuminate\Database\Eloquent\Builder<static>
newQueryForRestoration
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newEloquentBuilder($query) { return new static::$builder($query); }
Create a new Eloquent query builder for the model. @param \Illuminate\Database\Query\Builder $query @return \Illuminate\Database\Eloquent\Builder<*>
newEloquentBuilder
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function newBaseQueryBuilder() { return $this->getConnection()->query(); }
Get a new query builder instance for the connection. @return \Illuminate\Database\Query\Builder
newBaseQueryBuilder
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newPivot(self $parent, array $attributes, $table, $exists, $using = null) { return $using ? $using::fromRawAttributes($parent, $attributes, $table, $exists) : Pivot::fromAttributes($parent, $attributes, $table, $exists); }
Create a new pivot model instance. @param \Illuminate\Database\Eloquent\Model $parent @param array<string, mixed> $attributes @param string $table @param bool $exists @param string|null $using @return \Illuminate\Database\Eloquent\Relations\Pivot
newPivot
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function hasNamedScope($scope) { return method_exists($this, 'scope'.ucfirst($scope)) || static::isScopeMethodWithAttribute($scope); }
Determine if the model has a given scope. @param string $scope @return bool
hasNamedScope
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function callNamedScope($scope, array $parameters = []) { if ($this->isScopeMethodWithAttribute($scope)) { return $this->{$scope}(...$parameters); } return $this->{'scope'.ucfirst($scope)}(...$parameters); }
Apply the given named scope if possible. @param string $scope @param array $parameters @return mixed
callNamedScope
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected static function isScopeMethodWithAttribute(string $method) { return method_exists(static::class, $method) && (new ReflectionMethod(static::class, $method)) ->getAttributes(LocalScope::class) !== []; }
Determine if the given method has a scope attribute. @param string $method @return bool
isScopeMethodWithAttribute
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function toArray() { return $this->withoutRecursion( fn () => array_merge($this->attributesToArray(), $this->relationsToArray()), fn () => $this->attributesToArray(), ); }
Convert the model instance to an array. @return array
toArray
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function toJson($options = 0) { try { $json = json_encode($this->jsonSerialize(), $options | JSON_THROW_ON_ERROR); } catch (JsonException $e) { throw JsonEncodingException::forModel($this, $e->getMessage()); } return $json; }
Convert the model instance to JSON. @param int $options @return string @throws \Illuminate\Database\Eloquent\JsonEncodingException
toJson
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function jsonSerialize(): mixed { return $this->toArray(); }
Convert the object into something JSON serializable. @return mixed
jsonSerialize
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function fresh($with = []) { if (! $this->exists) { return; } return $this->setKeysForSelectQuery($this->newQueryWithoutScopes()) ->useWritePdo() ->with(is_string($with) ? func_get_args() : $with) ->first(); }
Reload a fresh model instance from the database. @param array|string $with @return static|null
fresh
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function refresh() { if (! $this->exists) { return $this; } $this->setRawAttributes( $this->setKeysForSelectQuery($this->newQueryWithoutScopes()) ->useWritePdo() ->firstOrFail() ->attributes ); $this->load((new BaseCollection($this->relations))->reject( fn ($relation) => $relation instanceof Pivot || (is_object($relation) && in_array(AsPivot::class, class_uses_recursive($relation), true)) )->keys()->all()); $this->syncOriginal(); return $this; }
Reload the current model instance with fresh attributes from the database. @return $this
refresh
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function replicate(?array $except = null) { $defaults = array_values(array_filter([ $this->getKeyName(), $this->getCreatedAtColumn(), $this->getUpdatedAtColumn(), ...$this->uniqueIds(), 'laravel_through_key', ])); $attributes = Arr::except( $this->getAttributes(), $except ? array_unique(array_merge($except, $defaults)) : $defaults ); return tap(new static, function ($instance) use ($attributes) { $instance->setRawAttributes($attributes); $instance->setRelations($this->relations); $instance->fireModelEvent('replicating', false); }); }
Clone the model into a new, non-existing instance. @param array|null $except @return static
replicate
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function replicateQuietly(?array $except = null) { return static::withoutEvents(fn () => $this->replicate($except)); }
Clone the model into a new, non-existing instance without raising any events. @param array|null $except @return static
replicateQuietly
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function is($model) { return ! is_null($model) && $this->getKey() === $model->getKey() && $this->getTable() === $model->getTable() && $this->getConnectionName() === $model->getConnectionName(); }
Determine if two models have the same ID and belong to the same table. @param \Illuminate\Database\Eloquent\Model|null $model @return bool
is
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function isNot($model) { return ! $this->is($model); }
Determine if two models are not the same. @param \Illuminate\Database\Eloquent\Model|null $model @return bool
isNot
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getConnection() { return static::resolveConnection($this->getConnectionName()); }
Get the database connection for the model. @return \Illuminate\Database\Connection
getConnection
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getConnectionName() { return $this->connection; }
Get the current connection name for the model. @return string|null
getConnectionName
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function setConnection($name) { $this->connection = $name; return $this; }
Set the connection associated with the model. @param string|null $name @return $this
setConnection
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function resolveConnection($connection = null) { return static::$resolver->connection($connection); }
Resolve a connection instance. @param string|null $connection @return \Illuminate\Database\Connection
resolveConnection
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function getConnectionResolver() { return static::$resolver; }
Get the connection resolver instance. @return \Illuminate\Database\ConnectionResolverInterface|null
getConnectionResolver
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function setConnectionResolver(Resolver $resolver) { static::$resolver = $resolver; }
Set the connection resolver instance. @param \Illuminate\Database\ConnectionResolverInterface $resolver @return void
setConnectionResolver
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function unsetConnectionResolver() { static::$resolver = null; }
Unset the connection resolver for models. @return void
unsetConnectionResolver
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getTable() { return $this->table ?? Str::snake(Str::pluralStudly(class_basename($this))); }
Get the table associated with the model. @return string
getTable
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function setTable($table) { $this->table = $table; return $this; }
Set the table associated with the model. @param string $table @return $this
setTable
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getKeyName() { return $this->primaryKey; }
Get the primary key for the model. @return string
getKeyName
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function setKeyName($key) { $this->primaryKey = $key; return $this; }
Set the primary key for the model. @param string $key @return $this
setKeyName
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getQualifiedKeyName() { return $this->qualifyColumn($this->getKeyName()); }
Get the table qualified key name. @return string
getQualifiedKeyName
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getKeyType() { return $this->keyType; }
Get the auto-incrementing key type. @return string
getKeyType
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function setKeyType($type) { $this->keyType = $type; return $this; }
Set the data type for the primary key. @param string $type @return $this
setKeyType
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getIncrementing() { return $this->incrementing; }
Get the value indicating whether the IDs are incrementing. @return bool
getIncrementing
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function setIncrementing($value) { $this->incrementing = $value; return $this; }
Set whether IDs are incrementing. @param bool $value @return $this
setIncrementing
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getKey() { return $this->getAttribute($this->getKeyName()); }
Get the value of the model's primary key. @return mixed
getKey
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getQueueableId() { return $this->getKey(); }
Get the queueable identity for the entity. @return mixed
getQueueableId
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getQueueableRelations() { return $this->withoutRecursion(function () { $relations = []; foreach ($this->getRelations() as $key => $relation) { if (! method_exists($this, $key)) { continue; } $relations[] = $key; if ($relation instanceof QueueableCollection) { foreach ($relation->getQueueableRelations() as $collectionValue) { $relations[] = $key.'.'.$collectionValue; } } if ($relation instanceof QueueableEntity) { foreach ($relation->getQueueableRelations() as $entityValue) { $relations[] = $key.'.'.$entityValue; } } } return array_unique($relations); }, []); }
Get the queueable relationships for the entity. @return array
getQueueableRelations
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getQueueableConnection() { return $this->getConnectionName(); }
Get the queueable connection for the entity. @return string|null
getQueueableConnection
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getRouteKey() { return $this->getAttribute($this->getRouteKeyName()); }
Get the value of the model's route key. @return mixed
getRouteKey
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getRouteKeyName() { return $this->getKeyName(); }
Get the route key for the model. @return string
getRouteKeyName
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function resolveRouteBinding($value, $field = null) { return $this->resolveRouteBindingQuery($this, $value, $field)->first(); }
Retrieve the model for a bound value. @param mixed $value @param string|null $field @return \Illuminate\Database\Eloquent\Model|null
resolveRouteBinding
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function resolveSoftDeletableRouteBinding($value, $field = null) { return $this->resolveRouteBindingQuery($this, $value, $field)->withTrashed()->first(); }
Retrieve the model for a bound value. @param mixed $value @param string|null $field @return \Illuminate\Database\Eloquent\Model|null
resolveSoftDeletableRouteBinding
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function resolveChildRouteBinding($childType, $value, $field) { return $this->resolveChildRouteBindingQuery($childType, $value, $field)->first(); }
Retrieve the child model for a bound value. @param string $childType @param mixed $value @param string|null $field @return \Illuminate\Database\Eloquent\Model|null
resolveChildRouteBinding
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function resolveSoftDeletableChildRouteBinding($childType, $value, $field) { return $this->resolveChildRouteBindingQuery($childType, $value, $field)->withTrashed()->first(); }
Retrieve the child model for a bound value. @param string $childType @param mixed $value @param string|null $field @return \Illuminate\Database\Eloquent\Model|null
resolveSoftDeletableChildRouteBinding
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function resolveChildRouteBindingQuery($childType, $value, $field) { $relationship = $this->{$this->childRouteBindingRelationshipName($childType)}(); $field = $field ?: $relationship->getRelated()->getRouteKeyName(); if ($relationship instanceof HasManyThrough || $relationship instanceof BelongsToMany) { $field = $relationship->getRelated()->qualifyColumn($field); } return $relationship instanceof Model ? $relationship->resolveRouteBindingQuery($relationship, $value, $field) : $relationship->getRelated()->resolveRouteBindingQuery($relationship, $value, $field); }
Retrieve the child model query for a bound value. @param string $childType @param mixed $value @param string|null $field @return \Illuminate\Database\Eloquent\Relations\Relation<\Illuminate\Database\Eloquent\Model, $this, *>
resolveChildRouteBindingQuery
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function childRouteBindingRelationshipName($childType) { return Str::plural(Str::camel($childType)); }
Retrieve the child route model binding relationship name for the given child type. @param string $childType @return string
childRouteBindingRelationshipName
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function resolveRouteBindingQuery($query, $value, $field = null) { return $query->where($field ?? $this->getRouteKeyName(), $value); }
Retrieve the model for a bound value. @param \Illuminate\Database\Eloquent\Model|\Illuminate\Contracts\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Relations\Relation $query @param mixed $value @param string|null $field @return \Illuminate\Contracts\Database\Eloquent\Builder
resolveRouteBindingQuery
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getForeignKey() { return Str::snake(class_basename($this)).'_'.$this->getKeyName(); }
Get the default foreign key name for the model. @return string
getForeignKey
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function getPerPage() { return $this->perPage; }
Get the number of models to return per page. @return int
getPerPage
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function setPerPage($perPage) { $this->perPage = $perPage; return $this; }
Set the number of models to return per page. @param int $perPage @return $this
setPerPage
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function preventsLazyLoading() { return static::$modelsShouldPreventLazyLoading; }
Determine if lazy loading is disabled. @return bool
preventsLazyLoading
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function isAutomaticallyEagerLoadingRelationships() { return static::$modelsShouldAutomaticallyEagerLoadRelationships; }
Determine if relationships are being automatically eager loaded when accessed. @return bool
isAutomaticallyEagerLoadingRelationships
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function preventsSilentlyDiscardingAttributes() { return static::$modelsShouldPreventSilentlyDiscardingAttributes; }
Determine if discarding guarded attribute fills is disabled. @return bool
preventsSilentlyDiscardingAttributes
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function preventsAccessingMissingAttributes() { return static::$modelsShouldPreventAccessingMissingAttributes; }
Determine if accessing missing attributes is disabled. @return bool
preventsAccessingMissingAttributes
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function broadcastChannelRoute() { return str_replace('\\', '.', get_class($this)).'.{'.Str::camel(class_basename($this)).'}'; }
Get the broadcast channel route definition that is associated with the given entity. @return string
broadcastChannelRoute
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function broadcastChannel() { return str_replace('\\', '.', get_class($this)).'.'.$this->getKey(); }
Get the broadcast channel name that is associated with the given entity. @return string
broadcastChannel
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function __get($key) { return $this->getAttribute($key); }
Dynamically retrieve attributes on the model. @param string $key @return mixed
__get
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function __set($key, $value) { $this->setAttribute($key, $value); }
Dynamically set attributes on the model. @param string $key @param mixed $value @return void
__set
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT