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 loadMissing($relations) { if (is_string($relations)) { $relations = func_get_args(); } foreach ($relations as $key => $value) { if (is_numeric($key)) { $key = $value; } $segments = explode('.', explode(':', $key)[0]); if (str_contains($key, ':')) { $segments[count($segments) - 1] .= ':'.explode(':', $key)[1]; } $path = []; foreach ($segments as $segment) { $path[] = [$segment => $segment]; } if (is_callable($value)) { $path[count($segments) - 1][end($segments)] = $value; } $this->loadMissingRelation($this, $path); } return $this; }
Load a set of relationships onto the collection if they are not already eager loaded. @param array<array-key, array|(callable(\Illuminate\Database\Eloquent\Relations\Relation<*, *, *>): mixed)|string>|string $relations @return $this
loadMissing
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function loadMissingRelationshipChain(array $tuples) { [$relation, $class] = array_shift($tuples); $this->filter(function ($model) use ($relation, $class) { return ! is_null($model) && ! $model->relationLoaded($relation) && $model::class === $class; })->load($relation); if (empty($tuples)) { return; } $models = $this->pluck($relation)->whereNotNull(); if ($models->first() instanceof BaseCollection) { $models = $models->collapse(); } (new static($models))->loadMissingRelationshipChain($tuples); }
Load a relationship path for models of the given type if it is not already eager loaded. @param array<int, <string, class-string>> $tuples @return void
loadMissingRelationshipChain
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
protected function loadMissingRelation(self $models, array $path) { $relation = array_shift($path); $name = explode(':', key($relation))[0]; if (is_string(reset($relation))) { $relation = reset($relation); } $models->filter(fn ($model) => ! is_null($model) && ! $model->relationLoaded($name))->load($relation); if (empty($path)) { return; } $models = $models->pluck($name)->filter(); if ($models->first() instanceof BaseCollection) { $models = $models->collapse(); } $this->loadMissingRelation(new static($models), $path); }
Load a relationship path if it is not already eager loaded. @param \Illuminate\Database\Eloquent\Collection<int, TModel> $models @param array $path @return void
loadMissingRelation
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function loadMorph($relation, $relations) { $this->pluck($relation) ->filter() ->groupBy(fn ($model) => get_class($model)) ->each(fn ($models, $className) => static::make($models)->load($relations[$className] ?? [])); return $this; }
Load a set of relationships onto the mixed relationship collection. @param string $relation @param array<array-key, array|(callable(\Illuminate\Database\Eloquent\Relations\Relation<*, *, *>): mixed)|string> $relations @return $this
loadMorph
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function loadMorphCount($relation, $relations) { $this->pluck($relation) ->filter() ->groupBy(fn ($model) => get_class($model)) ->each(fn ($models, $className) => static::make($models)->loadCount($relations[$className] ?? [])); return $this; }
Load a set of relationship counts onto the mixed relationship collection. @param string $relation @param array<array-key, array|(callable(\Illuminate\Database\Eloquent\Relations\Relation<*, *, *>): mixed)|string> $relations @return $this
loadMorphCount
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function contains($key, $operator = null, $value = null) { if (func_num_args() > 1 || $this->useAsCallable($key)) { return parent::contains(...func_get_args()); } if ($key instanceof Model) { return parent::contains(fn ($model) => $model->is($key)); } return parent::contains(fn ($model) => $model->getKey() == $key); }
Determine if a key exists in the collection. @param (callable(TModel, TKey): bool)|TModel|string|int $key @param mixed $operator @param mixed $value @return bool
contains
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function doesntContain($key, $operator = null, $value = null) { return ! $this->contains(...func_get_args()); }
Determine if a key does not exist in the collection. @param (callable(TModel, TKey): bool)|TModel|string|int $key @param mixed $operator @param mixed $value @return bool
doesntContain
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function modelKeys() { return array_map(fn ($model) => $model->getKey(), $this->items); }
Get the array of primary keys. @return array<int, array-key>
modelKeys
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function merge($items) { $dictionary = $this->getDictionary(); foreach ($items as $item) { $dictionary[$this->getDictionaryKey($item->getKey())] = $item; } return new static(array_values($dictionary)); }
Merge the collection with the given items. @param iterable<array-key, TModel> $items @return static
merge
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function map(callable $callback) { $result = parent::map($callback); return $result->contains(fn ($item) => ! $item instanceof Model) ? $result->toBase() : $result; }
Run a map over each of the items. @template TMapValue @param callable(TModel, TKey): TMapValue $callback @return \Illuminate\Support\Collection<TKey, TMapValue>|static<TKey, TMapValue>
map
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function mapWithKeys(callable $callback) { $result = parent::mapWithKeys($callback); return $result->contains(fn ($item) => ! $item instanceof Model) ? $result->toBase() : $result; }
Run an associative map over each of the items. The callback should return an associative array with a single key / value pair. @template TMapWithKeysKey of array-key @template TMapWithKeysValue @param callable(TModel, TKey): array<TMapWithKeysKey, TMapWithKeysValue> $callback @return \Illuminate\Support\Collection<TMapWithKeysKey, TMapWithKeysValue>|static<TMapWithKeysKey, TMapWithKeysValue>
mapWithKeys
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function fresh($with = []) { if ($this->isEmpty()) { return new static; } $model = $this->first(); $freshModels = $model->newQueryWithoutScopes() ->with(is_string($with) ? func_get_args() : $with) ->whereIn($model->getKeyName(), $this->modelKeys()) ->get() ->getDictionary(); return $this->filter(fn ($model) => $model->exists && isset($freshModels[$model->getKey()])) ->map(fn ($model) => $freshModels[$model->getKey()]); }
Reload a fresh model instance from the database for all the entities. @param array<array-key, string>|string $with @return static
fresh
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function diff($items) { $diff = new static; $dictionary = $this->getDictionary($items); foreach ($this->items as $item) { if (! isset($dictionary[$this->getDictionaryKey($item->getKey())])) { $diff->add($item); } } return $diff; }
Diff the collection with the given items. @param iterable<array-key, TModel> $items @return static
diff
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function intersect($items) { $intersect = new static; if (empty($items)) { return $intersect; } $dictionary = $this->getDictionary($items); foreach ($this->items as $item) { if (isset($dictionary[$this->getDictionaryKey($item->getKey())])) { $intersect->add($item); } } return $intersect; }
Intersect the collection with the given items. @param iterable<array-key, TModel> $items @return static
intersect
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function unique($key = null, $strict = false) { if (! is_null($key)) { return parent::unique($key, $strict); } return new static(array_values($this->getDictionary())); }
Return only unique items from the collection. @param (callable(TModel, TKey): mixed)|string|null $key @param bool $strict @return static
unique
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function only($keys) { if (is_null($keys)) { return new static($this->items); } $dictionary = Arr::only($this->getDictionary(), array_map($this->getDictionaryKey(...), (array) $keys)); return new static(array_values($dictionary)); }
Returns only the models from the collection with the specified keys. @param array<array-key, mixed>|null $keys @return static
only
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function except($keys) { if (is_null($keys)) { return new static($this->items); } $dictionary = Arr::except($this->getDictionary(), array_map($this->getDictionaryKey(...), (array) $keys)); return new static(array_values($dictionary)); }
Returns all models in the collection except the models with specified keys. @param array<array-key, mixed>|null $keys @return static
except
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function makeHidden($attributes) { return $this->each->makeHidden($attributes); }
Make the given, typically visible, attributes hidden across the entire collection. @param array<array-key, string>|string $attributes @return $this
makeHidden
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function makeVisible($attributes) { return $this->each->makeVisible($attributes); }
Make the given, typically hidden, attributes visible across the entire collection. @param array<array-key, string>|string $attributes @return $this
makeVisible
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function setVisible($visible) { return $this->each->setVisible($visible); }
Set the visible attributes across the entire collection. @param array<int, string> $visible @return $this
setVisible
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function setHidden($hidden) { return $this->each->setHidden($hidden); }
Set the hidden attributes across the entire collection. @param array<int, string> $hidden @return $this
setHidden
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function append($attributes) { return $this->each->append($attributes); }
Append an attribute across the entire collection. @param array<array-key, string>|string $attributes @return $this
append
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function getDictionary($items = null) { $items = is_null($items) ? $this->items : $items; $dictionary = []; foreach ($items as $value) { $dictionary[$this->getDictionaryKey($value->getKey())] = $value; } return $dictionary; }
Get a dictionary keyed by primary keys. @param iterable<array-key, TModel>|null $items @return array<array-key, TModel>
getDictionary
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function countBy($countBy = null) { return $this->toBase()->countBy($countBy); }
Count the number of items in the collection by a field or using a callback. @param (callable(TModel, TKey): array-key)|string|null $countBy @return \Illuminate\Support\Collection<array-key, int>
countBy
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function collapse() { return $this->toBase()->collapse(); }
Collapse the collection of items into a single array. @return \Illuminate\Support\Collection<int, mixed>
collapse
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function flatten($depth = INF) { return $this->toBase()->flatten($depth); }
Get a flattened array of the items in the collection. @param int $depth @return \Illuminate\Support\Collection<int, mixed>
flatten
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function flip() { return $this->toBase()->flip(); }
Flip the items in the collection. @return \Illuminate\Support\Collection<TModel, TKey>
flip
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function keys() { return $this->toBase()->keys(); }
Get the keys of the collection items. @return \Illuminate\Support\Collection<int, TKey>
keys
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function pad($size, $value) { return $this->toBase()->pad($size, $value); }
Pad collection to the specified length with a value. @template TPadValue @param int $size @param TPadValue $value @return \Illuminate\Support\Collection<int, TModel|TPadValue>
pad
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function partition($key, $operator = null, $value = null) { return parent::partition(...func_get_args())->toBase(); }
Partition the collection into two arrays using the given callback or key. @param (callable(TModel, TKey): bool)|TModel|string $key @param TModel|string|null $operator @param TModel|null $value @return \Illuminate\Support\Collection<int<0, 1>, static<TKey, TModel>>
partition
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function pluck($value, $key = null) { return $this->toBase()->pluck($value, $key); }
Get an array with the values of a given key. @param string|array<array-key, string>|null $value @param string|null $key @return \Illuminate\Support\Collection<array-key, mixed>
pluck
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function zip($items) { return $this->toBase()->zip(...func_get_args()); }
Zip the collection together with one or more arrays. @template TZipValue @param \Illuminate\Contracts\Support\Arrayable<array-key, TZipValue>|iterable<array-key, TZipValue> ...$items @return \Illuminate\Support\Collection<int, \Illuminate\Support\Collection<int, TModel|TZipValue>>
zip
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
protected function duplicateComparator($strict) { return fn ($a, $b) => $a->is($b); }
Get the comparison function to detect duplicates. @param bool $strict @return callable(TModel, TModel): bool
duplicateComparator
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function withRelationshipAutoloading() { $callback = fn ($tuples) => $this->loadMissingRelationshipChain($tuples); foreach ($this as $model) { if (! $model->hasRelationAutoloadCallback()) { $model->autoloadRelationsUsing($callback, $this); } } return $this; }
Enable relationship autoloading for all models in this collection. @return $this
withRelationshipAutoloading
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function getQueueableClass() { if ($this->isEmpty()) { return; } $class = $this->getQueueableModelClass($this->first()); $this->each(function ($model) use ($class) { if ($this->getQueueableModelClass($model) !== $class) { throw new LogicException('Queueing collections with multiple model types is not supported.'); } }); return $class; }
Get the type of the entities being queued. @return string|null @throws \LogicException
getQueueableClass
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
protected function getQueueableModelClass($model) { return method_exists($model, 'getQueueableClassName') ? $model->getQueueableClassName() : get_class($model); }
Get the queueable class name for the given model. @param \Illuminate\Database\Eloquent\Model $model @return string
getQueueableModelClass
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function getQueueableIds() { if ($this->isEmpty()) { return []; } return $this->first() instanceof QueueableEntity ? $this->map->getQueueableId()->all() : $this->modelKeys(); }
Get the identifiers for all of the entities. @return array<int, mixed>
getQueueableIds
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function getQueueableRelations() { if ($this->isEmpty()) { return []; } $relations = $this->map->getQueueableRelations()->all(); if (count($relations) === 0 || $relations === [[]]) { return []; } elseif (count($relations) === 1) { return reset($relations); } else { return array_intersect(...array_values($relations)); } }
Get the relationships of the entities being queued. @return array<int, string>
getQueueableRelations
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function getQueueableConnection() { if ($this->isEmpty()) { return; } $connection = $this->first()->getConnectionName(); $this->each(function ($model) use ($connection) { if ($model->getConnectionName() !== $connection) { throw new LogicException('Queueing collections with multiple model connections is not supported.'); } }); return $connection; }
Get the connection of the entities being queued. @return string|null @throws \LogicException
getQueueableConnection
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public function toQuery() { $model = $this->first(); if (! $model) { throw new LogicException('Unable to create query for empty collection.'); } $class = get_class($model); if ($this->reject(fn ($model) => $model instanceof $class)->isNotEmpty()) { throw new LogicException('Unable to create query for collection with mixed types.'); } return $model->newModelQuery()->whereKey($this->modelKeys()); }
Get the Eloquent query builder from the collection. @return \Illuminate\Database\Eloquent\Builder<TModel> @throws \LogicException
toQuery
php
illuminate/database
Eloquent/Collection.php
https://github.com/illuminate/database/blob/master/Eloquent/Collection.php
MIT
public static function query() { return parent::query(); }
Begin querying the model. @return TBuilder
query
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public function newEloquentBuilder($query) { return parent::newEloquentBuilder($query); }
Create a new Eloquent query builder for the model. @param \Illuminate\Database\Query\Builder $query @return TBuilder
newEloquentBuilder
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public function newQuery() { return parent::newQuery(); }
Get a new query builder for the model's table. @return TBuilder
newQuery
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public function newModelQuery() { return parent::newModelQuery(); }
Get a new query builder that doesn't have any global scopes or eager loading. @return TBuilder
newModelQuery
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public function newQueryWithoutRelationships() { return parent::newQueryWithoutRelationships(); }
Get a new query builder with no relationships loaded. @return TBuilder
newQueryWithoutRelationships
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public function newQueryWithoutScopes() { return parent::newQueryWithoutScopes(); }
Get a new query builder that doesn't have any global scopes. @return TBuilder
newQueryWithoutScopes
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public function newQueryWithoutScope($scope) { return parent::newQueryWithoutScope($scope); }
Get a new query instance without a given scope. @param \Illuminate\Database\Eloquent\Scope|string $scope @return TBuilder
newQueryWithoutScope
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public function newQueryForRestoration($ids) { return parent::newQueryForRestoration($ids); }
Get a new query to restore one or more models by their queueable IDs. @param array|int $ids @return TBuilder
newQueryForRestoration
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public static function on($connection = null) { return parent::on($connection); }
Begin querying the model on a given connection. @param string|null $connection @return TBuilder
on
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public static function onWriteConnection() { return parent::onWriteConnection(); }
Begin querying the model on the write connection. @return TBuilder
onWriteConnection
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public static function with($relations) { return parent::with($relations); }
Begin querying a model with eager loading. @param array|string $relations @return TBuilder
with
php
illuminate/database
Eloquent/HasBuilder.php
https://github.com/illuminate/database/blob/master/Eloquent/HasBuilder.php
MIT
public function newCollection(array $models = []) { static::$resolvedCollectionClasses[static::class] ??= ($this->resolveCollectionFromAttribute() ?? static::$collectionClass); $collection = new static::$resolvedCollectionClasses[static::class]($models); if (Model::isAutomaticallyEagerLoadingRelationships()) { $collection->withRelationshipAutoloading(); } return $collection; }
Create a new Eloquent Collection instance. @param array<array-key, \Illuminate\Database\Eloquent\Model> $models @return TCollection
newCollection
php
illuminate/database
Eloquent/HasCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/HasCollection.php
MIT
public function resolveCollectionFromAttribute() { $reflectionClass = new ReflectionClass(static::class); $attributes = $reflectionClass->getAttributes(CollectedBy::class); if (! isset($attributes[0]) || ! isset($attributes[0]->getArguments()[0])) { return; } return $attributes[0]->getArguments()[0]; }
Resolve the collection class name from the CollectedBy attribute. @return class-string<TCollection>|null
resolveCollectionFromAttribute
php
illuminate/database
Eloquent/HasCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/HasCollection.php
MIT
public function __construct(Builder $builder, $method) { $this->method = $method; $this->builder = $builder; }
Create a new proxy instance. @param \Illuminate\Database\Eloquent\Builder<*> $builder @param string $method
__construct
php
illuminate/database
Eloquent/HigherOrderBuilderProxy.php
https://github.com/illuminate/database/blob/master/Eloquent/HigherOrderBuilderProxy.php
MIT
public function __call($method, $parameters) { return $this->builder->{$this->method}(function ($value) use ($method, $parameters) { return $value->{$method}(...$parameters); }); }
Proxy a scope call onto the query builder. @param string $method @param array $parameters @return mixed
__call
php
illuminate/database
Eloquent/HigherOrderBuilderProxy.php
https://github.com/illuminate/database/blob/master/Eloquent/HigherOrderBuilderProxy.php
MIT
public function __construct($model, $column, $castType) { $class = get_class($model); parent::__construct("Call to undefined cast [{$castType}] on column [{$column}] in model [{$class}]."); $this->model = $class; $this->column = $column; $this->castType = $castType; }
Create a new exception instance. @param object $model @param string $column @param string $castType
__construct
php
illuminate/database
Eloquent/InvalidCastException.php
https://github.com/illuminate/database/blob/master/Eloquent/InvalidCastException.php
MIT
public static function forModel($model, $message) { return new static('Error encoding model ['.get_class($model).'] with ID ['.$model->getKey().'] to JSON: '.$message); }
Create a new JSON encoding exception for the model. @param mixed $model @param string $message @return static
forModel
php
illuminate/database
Eloquent/JsonEncodingException.php
https://github.com/illuminate/database/blob/master/Eloquent/JsonEncodingException.php
MIT
public static function forResource($resource, $message) { $model = $resource->resource; return new static('Error encoding resource ['.get_class($resource).'] with model ['.get_class($model).'] with ID ['.$model->getKey().'] to JSON: '.$message); }
Create a new JSON encoding exception for the resource. @param \Illuminate\Http\Resources\Json\JsonResource $resource @param string $message @return static
forResource
php
illuminate/database
Eloquent/JsonEncodingException.php
https://github.com/illuminate/database/blob/master/Eloquent/JsonEncodingException.php
MIT
public static function forAttribute($model, $key, $message) { $class = get_class($model); return new static("Unable to encode attribute [{$key}] for model [{$class}] to JSON: {$message}."); }
Create a new JSON encoding exception for an attribute. @param mixed $model @param mixed $key @param string $message @return static
forAttribute
php
illuminate/database
Eloquent/JsonEncodingException.php
https://github.com/illuminate/database/blob/master/Eloquent/JsonEncodingException.php
MIT
public function pruneAll(int $chunkSize = 1000) { $query = tap($this->prunable(), function ($query) use ($chunkSize) { $query->when(! $query->getQuery()->limit, function ($query) use ($chunkSize) { $query->limit($chunkSize); }); }); $total = 0; $softDeletable = in_array(SoftDeletes::class, class_uses_recursive(get_class($this))); do { $total += $count = $softDeletable ? $query->forceDelete() : $query->delete(); if ($count > 0) { event(new ModelsPruned(static::class, $total)); } } while ($count > 0); return $total; }
Prune all prunable models in the database. @param int $chunkSize @return int
pruneAll
php
illuminate/database
Eloquent/MassPrunable.php
https://github.com/illuminate/database/blob/master/Eloquent/MassPrunable.php
MIT
public function prunable() { throw new LogicException('Please implement the prunable method on your model.'); }
Get the prunable model query. @return \Illuminate\Database\Eloquent\Builder<static>
prunable
php
illuminate/database
Eloquent/MassPrunable.php
https://github.com/illuminate/database/blob/master/Eloquent/MassPrunable.php
MIT
public function __construct($model, $key) { parent::__construct(sprintf( 'The attribute [%s] either does not exist or was not retrieved for model [%s].', $key, get_class($model) )); }
Create a new missing attribute exception instance. @param \Illuminate\Database\Eloquent\Model $model @param string $key
__construct
php
illuminate/database
Eloquent/MissingAttributeException.php
https://github.com/illuminate/database/blob/master/Eloquent/MissingAttributeException.php
MIT
public function __construct(array $attributes = []) { $this->bootIfNotBooted(); $this->initializeTraits(); $this->syncOriginal(); $this->fill($attributes); }
Create a new Eloquent model instance. @param array<string, mixed> $attributes
__construct
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function bootIfNotBooted() { if (! isset(static::$booted[static::class])) { if (isset(static::$booting[static::class])) { throw new LogicException('The ['.__METHOD__.'] method may not be called on model ['.static::class.'] while it is being booted.'); } static::$booting[static::class] = true; $this->fireModelEvent('booting', false); static::booting(); static::boot(); static::$booted[static::class] = true; unset(static::$booting[static::class]); static::booted(); static::$bootedCallbacks[static::class] ??= []; foreach (static::$bootedCallbacks[static::class] as $callback) { $callback(); } $this->fireModelEvent('booted', false); } }
Check if the model needs to be booted and if so, do it. @return void
bootIfNotBooted
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected static function booting() { // }
Perform any actions required before the model boots. @return void
booting
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected static function boot() { static::bootTraits(); }
Bootstrap the model and its traits. @return void
boot
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected static function bootTraits() { $class = static::class; $booted = []; static::$traitInitializers[$class] = []; foreach (class_uses_recursive($class) as $trait) { $method = 'boot'.class_basename($trait); if (method_exists($class, $method) && ! in_array($method, $booted)) { forward_static_call([$class, $method]); $booted[] = $method; } if (method_exists($class, $method = 'initialize'.class_basename($trait))) { static::$traitInitializers[$class][] = $method; static::$traitInitializers[$class] = array_unique( static::$traitInitializers[$class] ); } } }
Boot all of the bootable traits on the model. @return void
bootTraits
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected function initializeTraits() { foreach (static::$traitInitializers[static::class] as $method) { $this->{$method}(); } }
Initialize any initializable traits on the model. @return void
initializeTraits
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected static function booted() { // }
Perform any actions required after the model boots. @return void
booted
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
protected static function whenBooted(Closure $callback) { static::$bootedCallbacks[static::class] ??= []; static::$bootedCallbacks[static::class][] = $callback; }
Register a closure to be executed after the model has booted. @param \Closure $callback @return void
whenBooted
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function clearBootedModels() { static::$booted = []; static::$bootedCallbacks = []; static::$globalScopes = []; }
Clear the list of booted models so they will be re-booted. @return void
clearBootedModels
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function withoutTouching(callable $callback) { static::withoutTouchingOn([static::class], $callback); }
Disables relationship model touching for the current class during given callback scope. @param callable $callback @return void
withoutTouching
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function withoutTouchingOn(array $models, callable $callback) { static::$ignoreOnTouch = array_values(array_merge(static::$ignoreOnTouch, $models)); try { $callback(); } finally { static::$ignoreOnTouch = array_values(array_diff(static::$ignoreOnTouch, $models)); } }
Disables relationship model touching for the given model classes during given callback scope. @param array $models @param callable $callback @return void
withoutTouchingOn
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function isIgnoringTouch($class = null) { $class = $class ?: static::class; if (! get_class_vars($class)['timestamps'] || ! $class::UPDATED_AT) { return true; } foreach (static::$ignoreOnTouch as $ignoredClass) { if ($class === $ignoredClass || is_subclass_of($class, $ignoredClass)) { return true; } } return false; }
Determine if the given model is ignoring touches. @param string|null $class @return bool
isIgnoringTouch
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function shouldBeStrict(bool $shouldBeStrict = true) { static::preventLazyLoading($shouldBeStrict); static::preventSilentlyDiscardingAttributes($shouldBeStrict); static::preventAccessingMissingAttributes($shouldBeStrict); }
Indicate that models should prevent lazy loading, silently discarding attributes, and accessing missing attributes. @param bool $shouldBeStrict @return void
shouldBeStrict
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function preventLazyLoading($value = true) { static::$modelsShouldPreventLazyLoading = $value; }
Prevent model relationships from being lazy loaded. @param bool $value @return void
preventLazyLoading
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function automaticallyEagerLoadRelationships($value = true) { static::$modelsShouldAutomaticallyEagerLoadRelationships = $value; }
Determine if model relationships should be automatically eager loaded when accessed. @param bool $value @return void
automaticallyEagerLoadRelationships
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function handleLazyLoadingViolationUsing(?callable $callback) { static::$lazyLoadingViolationCallback = $callback; }
Register a callback that is responsible for handling lazy loading violations. @param callable|null $callback @return void
handleLazyLoadingViolationUsing
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function preventSilentlyDiscardingAttributes($value = true) { static::$modelsShouldPreventSilentlyDiscardingAttributes = $value; }
Prevent non-fillable attributes from being silently discarded. @param bool $value @return void
preventSilentlyDiscardingAttributes
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function handleDiscardedAttributeViolationUsing(?callable $callback) { static::$discardedAttributeViolationCallback = $callback; }
Register a callback that is responsible for handling discarded attribute violations. @param callable|null $callback @return void
handleDiscardedAttributeViolationUsing
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function preventAccessingMissingAttributes($value = true) { static::$modelsShouldPreventAccessingMissingAttributes = $value; }
Prevent accessing missing attributes on retrieved models. @param bool $value @return void
preventAccessingMissingAttributes
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function handleMissingAttributeViolationUsing(?callable $callback) { static::$missingAttributeViolationCallback = $callback; }
Register a callback that is responsible for handling missing attribute violations. @param callable|null $callback @return void
handleMissingAttributeViolationUsing
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function withoutBroadcasting(callable $callback) { $isBroadcasting = static::$isBroadcasting; static::$isBroadcasting = false; try { return $callback(); } finally { static::$isBroadcasting = $isBroadcasting; } }
Execute a callback without broadcasting any model events for all model types. @param callable $callback @return mixed
withoutBroadcasting
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function fill(array $attributes) { $totallyGuarded = $this->totallyGuarded(); $fillable = $this->fillableFromArray($attributes); foreach ($fillable as $key => $value) { // The developers may choose to place some attributes in the "fillable" array // which means only those attributes may be set through mass assignment to // the model, and all others will just get ignored for security reasons. if ($this->isFillable($key)) { $this->setAttribute($key, $value); } elseif ($totallyGuarded || static::preventsSilentlyDiscardingAttributes()) { if (isset(static::$discardedAttributeViolationCallback)) { call_user_func(static::$discardedAttributeViolationCallback, $this, [$key]); } else { throw new MassAssignmentException(sprintf( 'Add [%s] to fillable property to allow mass assignment on [%s].', $key, get_class($this) )); } } } if (count($attributes) !== count($fillable) && static::preventsSilentlyDiscardingAttributes()) { $keys = array_diff(array_keys($attributes), array_keys($fillable)); if (isset(static::$discardedAttributeViolationCallback)) { call_user_func(static::$discardedAttributeViolationCallback, $this, $keys); } else { throw new MassAssignmentException(sprintf( 'Add fillable property [%s] to allow mass assignment on [%s].', implode(', ', $keys), get_class($this) )); } } return $this; }
Fill the model with an array of attributes. @param array<string, mixed> $attributes @return $this @throws \Illuminate\Database\Eloquent\MassAssignmentException
fill
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function forceFill(array $attributes) { return static::unguarded(fn () => $this->fill($attributes)); }
Fill the model with an array of attributes. Force mass assignment. @param array<string, mixed> $attributes @return $this
forceFill
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function qualifyColumn($column) { if (str_contains($column, '.')) { return $column; } return $this->getTable().'.'.$column; }
Qualify the given column name by the model's table. @param string $column @return string
qualifyColumn
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function qualifyColumns($columns) { return (new BaseCollection($columns)) ->map(fn ($column) => $this->qualifyColumn($column)) ->all(); }
Qualify the given columns with the model's table. @param array $columns @return array
qualifyColumns
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newInstance($attributes = [], $exists = false) { // This method just provides a convenient way for us to generate fresh model // instances of this current model. It is particularly useful during the // hydration of new objects via the Eloquent query builder instances. $model = new static; $model->exists = $exists; $model->setConnection( $this->getConnectionName() ); $model->setTable($this->getTable()); $model->mergeCasts($this->casts); $model->fill((array) $attributes); return $model; }
Create a new instance of the given model. @param array<string, mixed> $attributes @param bool $exists @return static
newInstance
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function newFromBuilder($attributes = [], $connection = null) { $model = $this->newInstance([], true); $model->setRawAttributes((array) $attributes, true); $model->setConnection($connection ?: $this->getConnectionName()); $model->fireModelEvent('retrieved', false); return $model; }
Create a new model instance that is existing. @param array<string, mixed> $attributes @param string|null $connection @return static
newFromBuilder
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function on($connection = null) { // First we will just create a fresh instance of this model, and then we can set the // connection on the model so that it is used for the queries we execute, as well // as being set on every relation we retrieve without a custom connection name. $instance = new static; $instance->setConnection($connection); return $instance->newQuery(); }
Begin querying the model on a given connection. @param string|null $connection @return \Illuminate\Database\Eloquent\Builder<static>
on
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function onWriteConnection() { return static::query()->useWritePdo(); }
Begin querying the model on the write connection. @return \Illuminate\Database\Eloquent\Builder<static>
onWriteConnection
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function all($columns = ['*']) { return static::query()->get( is_array($columns) ? $columns : func_get_args() ); }
Get all of the models from the database. @param array|string $columns @return \Illuminate\Database\Eloquent\Collection<int, static>
all
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function with($relations) { return static::query()->with( is_string($relations) ? func_get_args() : $relations ); }
Begin querying a model with eager loading. @param array|string $relations @return \Illuminate\Database\Eloquent\Builder<static>
with
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function load($relations) { $query = $this->newQueryWithoutRelationships()->with( is_string($relations) ? func_get_args() : $relations ); $query->eagerLoadRelations([$this]); return $this; }
Eager load relations on the model. @param array|string $relations @return $this
load
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMorph($relation, $relations) { if (! $this->{$relation}) { return $this; } $className = get_class($this->{$relation}); $this->{$relation}->load($relations[$className] ?? []); return $this; }
Eager load relationships on the polymorphic relation of a model. @param string $relation @param array $relations @return $this
loadMorph
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMissing($relations) { $relations = is_string($relations) ? func_get_args() : $relations; $this->newCollection([$this])->loadMissing($relations); return $this; }
Eager load relations on the model if they are not already eager loaded. @param array|string $relations @return $this
loadMissing
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadAggregate($relations, $column, $function = null) { $this->newCollection([$this])->loadAggregate($relations, $column, $function); return $this; }
Eager load relation's column aggregations on the model. @param array|string $relations @param string $column @param string|null $function @return $this
loadAggregate
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadCount($relations) { $relations = is_string($relations) ? func_get_args() : $relations; return $this->loadAggregate($relations, '*', 'count'); }
Eager load relation counts on the model. @param array|string $relations @return $this
loadCount
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMax($relations, $column) { return $this->loadAggregate($relations, $column, 'max'); }
Eager load relation max column values on the model. @param array|string $relations @param string $column @return $this
loadMax
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function loadMin($relations, $column) { return $this->loadAggregate($relations, $column, 'min'); }
Eager load relation min column values on the model. @param array|string $relations @param string $column @return $this
loadMin
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT