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 offsetExists($offset): bool { $shouldPrevent = static::$modelsShouldPreventAccessingMissingAttributes; static::$modelsShouldPreventAccessingMissingAttributes = false; $result = ! is_null($this->getAttribute($offset)); static::$modelsShouldPreventAccessingMissingAttributes = $shouldPrevent; return $result; }
Determine if the given attribute exists. @param mixed $offset @return bool
offsetExists
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function offsetGet($offset): mixed { return $this->getAttribute($offset); }
Get the value for a given offset. @param mixed $offset @return mixed
offsetGet
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function offsetSet($offset, $value): void { $this->setAttribute($offset, $value); }
Set the value for a given offset. @param mixed $offset @param mixed $value @return void
offsetSet
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function offsetUnset($offset): void { unset($this->attributes[$offset], $this->relations[$offset], $this->attributeCastCache[$offset]); }
Unset the value for a given offset. @param mixed $offset @return void
offsetUnset
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function __isset($key) { return $this->offsetExists($key); }
Determine if an attribute or relation exists on the model. @param string $key @return bool
__isset
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function __unset($key) { $this->offsetUnset($key); }
Unset an attribute on the model. @param string $key @return void
__unset
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function __call($method, $parameters) { if (in_array($method, ['increment', 'decrement', 'incrementQuietly', 'decrementQuietly'])) { return $this->$method(...$parameters); } if ($resolver = $this->relationResolver(static::class, $method)) { return $resolver($this); } if (Str::startsWith($method, 'through') && method_exists($this, $relationMethod = (new SupportStringable($method))->after('through')->lcfirst()->toString())) { return $this->through($relationMethod); } return $this->forwardCallTo($this->newQuery(), $method, $parameters); }
Handle dynamic method calls into the model. @param string $method @param array $parameters @return mixed
__call
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public static function __callStatic($method, $parameters) { if (static::isScopeMethodWithAttribute($method)) { return static::query()->$method(...$parameters); } return (new static)->$method(...$parameters); }
Handle dynamic static method calls into the model. @param string $method @param array $parameters @return mixed
__callStatic
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function __toString() { return $this->escapeWhenCastingToString ? e($this->toJson()) : $this->toJson(); }
Convert the model to its string representation. @return string
__toString
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function escapeWhenCastingToString($escape = true) { $this->escapeWhenCastingToString = $escape; return $this; }
Indicate that the object's string representation should be escaped when __toString is invoked. @param bool $escape @return $this
escapeWhenCastingToString
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function __sleep() { $this->mergeAttributesFromCachedCasts(); $this->classCastCache = []; $this->attributeCastCache = []; $this->relationAutoloadCallback = null; $this->relationAutoloadContext = null; return array_keys(get_object_vars($this)); }
Prepare the object for serialization. @return array
__sleep
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function __wakeup() { $this->bootIfNotBooted(); $this->initializeTraits(); if (static::isAutomaticallyEagerLoadingRelationships()) { $this->withRelationshipAutoloading(); } }
When a model is being unserialized, check if it needs to be booted. @return void
__wakeup
php
illuminate/database
Eloquent/Model.php
https://github.com/illuminate/database/blob/master/Eloquent/Model.php
MIT
public function __construct(Application $app) { $this->app = $app; }
Create a new model inspector instance. @param \Illuminate\Contracts\Foundation\Application $app
__construct
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
public function inspect($model, $connection = null) { $class = $this->qualifyModel($model); /** @var \Illuminate\Database\Eloquent\Model $model */ $model = $this->app->make($class); if ($connection !== null) { $model->setConnection($connection); } return [ 'class' => get_class($model), 'database' => $model->getConnection()->getName(), 'table' => $model->getConnection()->getTablePrefix().$model->getTable(), 'policy' => $this->getPolicy($model), 'attributes' => $this->getAttributes($model), 'relations' => $this->getRelations($model), 'events' => $this->getEvents($model), 'observers' => $this->getObservers($model), 'collection' => $this->getCollectedBy($model), 'builder' => $this->getBuilder($model), ]; }
Extract model details for the given model. @param class-string<\Illuminate\Database\Eloquent\Model>|string $model @param string|null $connection @return array{"class": class-string<\Illuminate\Database\Eloquent\Model>, database: string, table: string, policy: class-string|null, attributes: \Illuminate\Support\Collection, relations: \Illuminate\Support\Collection, events: \Illuminate\Support\Collection, observers: \Illuminate\Support\Collection, collection: class-string<\Illuminate\Database\Eloquent\Collection<\Illuminate\Database\Eloquent\Model>>, builder: class-string<\Illuminate\Database\Eloquent\Builder<\Illuminate\Database\Eloquent\Model>>} @throws BindingResolutionException
inspect
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getAttributes($model) { $connection = $model->getConnection(); $schema = $connection->getSchemaBuilder(); $table = $model->getTable(); $columns = $schema->getColumns($table); $indexes = $schema->getIndexes($table); return (new BaseCollection($columns)) ->map(fn ($column) => [ 'name' => $column['name'], 'type' => $column['type'], 'increments' => $column['auto_increment'], 'nullable' => $column['nullable'], 'default' => $this->getColumnDefault($column, $model), 'unique' => $this->columnIsUnique($column['name'], $indexes), 'fillable' => $model->isFillable($column['name']), 'hidden' => $this->attributeIsHidden($column['name'], $model), 'appended' => null, 'cast' => $this->getCastType($column['name'], $model), ]) ->merge($this->getVirtualAttributes($model, $columns)); }
Get the column attributes for the given model. @param \Illuminate\Database\Eloquent\Model $model @return \Illuminate\Support\Collection<int, array<string, mixed>>
getAttributes
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getVirtualAttributes($model, $columns) { $class = new ReflectionClass($model); return (new BaseCollection($class->getMethods())) ->reject( fn (ReflectionMethod $method) => $method->isStatic() || $method->isAbstract() || $method->getDeclaringClass()->getName() === Model::class ) ->mapWithKeys(function (ReflectionMethod $method) use ($model) { if (preg_match('/^get(.+)Attribute$/', $method->getName(), $matches) === 1) { return [Str::snake($matches[1]) => 'accessor']; } elseif ($model->hasAttributeMutator($method->getName())) { return [Str::snake($method->getName()) => 'attribute']; } else { return []; } }) ->reject(fn ($cast, $name) => (new BaseCollection($columns))->contains('name', $name)) ->map(fn ($cast, $name) => [ 'name' => $name, 'type' => null, 'increments' => false, 'nullable' => null, 'default' => null, 'unique' => null, 'fillable' => $model->isFillable($name), 'hidden' => $this->attributeIsHidden($name, $model), 'appended' => $model->hasAppended($name), 'cast' => $cast, ]) ->values(); }
Get the virtual (non-column) attributes for the given model. @param \Illuminate\Database\Eloquent\Model $model @param array $columns @return \Illuminate\Support\Collection
getVirtualAttributes
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getRelations($model) { return (new BaseCollection(get_class_methods($model))) ->map(fn ($method) => new ReflectionMethod($model, $method)) ->reject( fn (ReflectionMethod $method) => $method->isStatic() || $method->isAbstract() || $method->getDeclaringClass()->getName() === Model::class || $method->getNumberOfParameters() > 0 ) ->filter(function (ReflectionMethod $method) { if ($method->getReturnType() instanceof ReflectionNamedType && is_subclass_of($method->getReturnType()->getName(), Relation::class)) { return true; } $file = new SplFileObject($method->getFileName()); $file->seek($method->getStartLine() - 1); $code = ''; while ($file->key() < $method->getEndLine()) { $code .= trim($file->current()); $file->next(); } return (new BaseCollection($this->relationMethods)) ->contains(fn ($relationMethod) => str_contains($code, '$this->'.$relationMethod.'(')); }) ->map(function (ReflectionMethod $method) use ($model) { $relation = $method->invoke($model); if (! $relation instanceof Relation) { return null; } return [ 'name' => $method->getName(), 'type' => Str::afterLast(get_class($relation), '\\'), 'related' => get_class($relation->getRelated()), ]; }) ->filter() ->values(); }
Get the relations from the given model. @param \Illuminate\Database\Eloquent\Model $model @return \Illuminate\Support\Collection
getRelations
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getPolicy($model) { $policy = Gate::getPolicyFor($model::class); return $policy ? $policy::class : null; }
Get the first policy associated with this model. @param \Illuminate\Database\Eloquent\Model $model @return string|null
getPolicy
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getEvents($model) { return (new BaseCollection($model->dispatchesEvents())) ->map(fn (string $class, string $event) => [ 'event' => $event, 'class' => $class, ])->values(); }
Get the events that the model dispatches. @param \Illuminate\Database\Eloquent\Model $model @return \Illuminate\Support\Collection
getEvents
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getObservers($model) { $listeners = $this->app->make('events')->getRawListeners(); // Get the Eloquent observers for this model... $listeners = array_filter($listeners, function ($v, $key) use ($model) { return Str::startsWith($key, 'eloquent.') && Str::endsWith($key, $model::class); }, ARRAY_FILTER_USE_BOTH); // Format listeners Eloquent verb => Observer methods... $extractVerb = function ($key) { preg_match('/eloquent.([a-zA-Z]+)\: /', $key, $matches); return $matches[1] ?? '?'; }; $formatted = []; foreach ($listeners as $key => $observerMethods) { $formatted[] = [ 'event' => $extractVerb($key), 'observer' => array_map(fn ($obs) => is_string($obs) ? $obs : 'Closure', $observerMethods), ]; } return new BaseCollection($formatted); }
Get the observers watching this model. @param \Illuminate\Database\Eloquent\Model $model @return \Illuminate\Support\Collection @throws BindingResolutionException
getObservers
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getCollectedBy($model) { return $model->newCollection()::class; }
Get the collection class being used by the model. @param \Illuminate\Database\Eloquent\Model $model @return class-string<\Illuminate\Database\Eloquent\Collection>
getCollectedBy
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getBuilder($model) { return $model->newQuery()::class; }
Get the builder class being used by the model. @template TModel of \Illuminate\Database\Eloquent\Model @param TModel $model @return class-string<\Illuminate\Database\Eloquent\Builder<TModel>>
getBuilder
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function qualifyModel(string $model) { if (str_contains($model, '\\') && class_exists($model)) { return $model; } $model = ltrim($model, '\\/'); $model = str_replace('/', '\\', $model); $rootNamespace = $this->app->getNamespace(); if (Str::startsWith($model, $rootNamespace)) { return $model; } return is_dir(app_path('Models')) ? $rootNamespace.'Models\\'.$model : $rootNamespace.$model; }
Qualify the given model class base name. @param string $model @return class-string<\Illuminate\Database\Eloquent\Model> @see \Illuminate\Console\GeneratorCommand
qualifyModel
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getCastType($column, $model) { if ($model->hasGetMutator($column) || $model->hasSetMutator($column)) { return 'accessor'; } if ($model->hasAttributeMutator($column)) { return 'attribute'; } return $this->getCastsWithDates($model)->get($column) ?? null; }
Get the cast type for the given column. @param string $column @param \Illuminate\Database\Eloquent\Model $model @return string|null
getCastType
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getCastsWithDates($model) { return (new BaseCollection($model->getDates())) ->filter() ->flip() ->map(fn () => 'datetime') ->merge($model->getCasts()); }
Get the model casts, including any date casts. @param \Illuminate\Database\Eloquent\Model $model @return \Illuminate\Support\Collection
getCastsWithDates
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function attributeIsHidden($attribute, $model) { if (count($model->getHidden()) > 0) { return in_array($attribute, $model->getHidden()); } if (count($model->getVisible()) > 0) { return ! in_array($attribute, $model->getVisible()); } return false; }
Determine if the given attribute is hidden. @param string $attribute @param \Illuminate\Database\Eloquent\Model $model @return bool
attributeIsHidden
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function getColumnDefault($column, $model) { $attributeDefault = $model->getAttributes()[$column['name']] ?? null; return enum_value($attributeDefault) ?? $column['default']; }
Get the default value for the given column. @param array<string, mixed> $column @param \Illuminate\Database\Eloquent\Model $model @return mixed|null
getColumnDefault
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
protected function columnIsUnique($column, $indexes) { return (new BaseCollection($indexes))->contains( fn ($index) => count($index['columns']) === 1 && $index['columns'][0] === $column && $index['unique'] ); }
Determine if the given attribute is unique. @param string $column @param array $indexes @return bool
columnIsUnique
php
illuminate/database
Eloquent/ModelInspector.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelInspector.php
MIT
public function setModel($model, $ids = []) { $this->model = $model; $this->ids = Arr::wrap($ids); $this->message = "No query results for model [{$model}]"; if (count($this->ids) > 0) { $this->message .= ' '.implode(', ', $this->ids); } else { $this->message .= '.'; } return $this; }
Set the affected Eloquent model and instance ids. @param class-string<TModel> $model @param array<int, int|string>|int|string $ids @return $this
setModel
php
illuminate/database
Eloquent/ModelNotFoundException.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelNotFoundException.php
MIT
public function getModel() { return $this->model; }
Get the affected Eloquent model. @return class-string<TModel>
getModel
php
illuminate/database
Eloquent/ModelNotFoundException.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelNotFoundException.php
MIT
public function getIds() { return $this->ids; }
Get the affected Eloquent model IDs. @return array<int, int|string>
getIds
php
illuminate/database
Eloquent/ModelNotFoundException.php
https://github.com/illuminate/database/blob/master/Eloquent/ModelNotFoundException.php
MIT
public function __construct($rootModel, $localRelationship) { $this->rootModel = $rootModel; $this->localRelationship = $localRelationship; }
Create a pending has-many-through or has-one-through relationship. @param TDeclaringModel $rootModel @param TLocalRelationship $localRelationship
__construct
php
illuminate/database
Eloquent/PendingHasThroughRelationship.php
https://github.com/illuminate/database/blob/master/Eloquent/PendingHasThroughRelationship.php
MIT
public function has($callback) { if (is_string($callback)) { $callback = fn () => $this->localRelationship->getRelated()->{$callback}(); } $distantRelation = $callback($this->localRelationship->getRelated()); if ($distantRelation instanceof HasMany || $this->localRelationship instanceof HasMany) { $returnedRelation = $this->rootModel->hasManyThrough( $distantRelation->getRelated()::class, $this->localRelationship->getRelated()::class, $this->localRelationship->getForeignKeyName(), $distantRelation->getForeignKeyName(), $this->localRelationship->getLocalKeyName(), $distantRelation->getLocalKeyName(), ); } else { $returnedRelation = $this->rootModel->hasOneThrough( $distantRelation->getRelated()::class, $this->localRelationship->getRelated()::class, $this->localRelationship->getForeignKeyName(), $distantRelation->getForeignKeyName(), $this->localRelationship->getLocalKeyName(), $distantRelation->getLocalKeyName(), ); } if ($this->localRelationship instanceof MorphOneOrMany) { $returnedRelation->where($this->localRelationship->getQualifiedMorphType(), $this->localRelationship->getMorphClass()); } return $returnedRelation; }
Define the distant relationship that this model has. @template TRelatedModel of \Illuminate\Database\Eloquent\Model @param string|(callable(TIntermediateModel): (\Illuminate\Database\Eloquent\Relations\HasOne<TRelatedModel, TIntermediateModel>|\Illuminate\Database\Eloquent\Relations\HasMany<TRelatedModel, TIntermediateModel>|\Illuminate\Database\Eloquent\Relations\MorphOneOrMany<TRelatedModel, TIntermediateModel>)) $callback @return ( $callback is string ? \Illuminate\Database\Eloquent\Relations\HasManyThrough<\Illuminate\Database\Eloquent\Model, TIntermediateModel, TDeclaringModel>|\Illuminate\Database\Eloquent\Relations\HasOneThrough<\Illuminate\Database\Eloquent\Model, TIntermediateModel, TDeclaringModel> : ( TLocalRelationship is \Illuminate\Database\Eloquent\Relations\HasMany<TIntermediateModel, TDeclaringModel> ? \Illuminate\Database\Eloquent\Relations\HasManyThrough<TRelatedModel, TIntermediateModel, TDeclaringModel> : ( $callback is callable(TIntermediateModel): \Illuminate\Database\Eloquent\Relations\HasMany<TRelatedModel, TIntermediateModel> ? \Illuminate\Database\Eloquent\Relations\HasManyThrough<TRelatedModel, TIntermediateModel, TDeclaringModel> : \Illuminate\Database\Eloquent\Relations\HasOneThrough<TRelatedModel, TIntermediateModel, TDeclaringModel> ) ) )
has
php
illuminate/database
Eloquent/PendingHasThroughRelationship.php
https://github.com/illuminate/database/blob/master/Eloquent/PendingHasThroughRelationship.php
MIT
public function __call($method, $parameters) { if (Str::startsWith($method, 'has')) { return $this->has((new Stringable($method))->after('has')->lcfirst()->toString()); } throw new BadMethodCallException(sprintf( 'Call to undefined method %s::%s()', static::class, $method )); }
Handle dynamic method calls into the model. @param string $method @param array $parameters @return mixed
__call
php
illuminate/database
Eloquent/PendingHasThroughRelationship.php
https://github.com/illuminate/database/blob/master/Eloquent/PendingHasThroughRelationship.php
MIT
public function pruneAll(int $chunkSize = 1000) { $total = 0; $this->prunable() ->when(in_array(SoftDeletes::class, class_uses_recursive(static::class)), function ($query) { $query->withTrashed(); })->chunkById($chunkSize, function ($models) use (&$total) { $models->each(function ($model) use (&$total) { try { $model->prune(); $total++; } catch (Throwable $e) { $handler = app(ExceptionHandler::class); if ($handler) { $handler->report($e); } else { throw $e; } } }); event(new ModelsPruned(static::class, $total)); }); return $total; }
Prune all prunable models in the database. @param int $chunkSize @return int
pruneAll
php
illuminate/database
Eloquent/Prunable.php
https://github.com/illuminate/database/blob/master/Eloquent/Prunable.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/Prunable.php
https://github.com/illuminate/database/blob/master/Eloquent/Prunable.php
MIT
public function prune() { $this->pruning(); return in_array(SoftDeletes::class, class_uses_recursive(static::class)) ? $this->forceDelete() : $this->delete(); }
Prune the model in the database. @return bool|null
prune
php
illuminate/database
Eloquent/Prunable.php
https://github.com/illuminate/database/blob/master/Eloquent/Prunable.php
MIT
protected function pruning() { // }
Prepare the model for pruning. @return void
pruning
php
illuminate/database
Eloquent/Prunable.php
https://github.com/illuminate/database/blob/master/Eloquent/Prunable.php
MIT
public function resolve($type, $id) { $instance = (new $type)->find($id); if ($instance) { return $instance; } throw new EntityNotFoundException($type, $id); }
Resolve the entity for the given ID. @param string $type @param mixed $id @return mixed @throws \Illuminate\Contracts\Queue\EntityNotFoundException
resolve
php
illuminate/database
Eloquent/QueueEntityResolver.php
https://github.com/illuminate/database/blob/master/Eloquent/QueueEntityResolver.php
MIT
public static function make($model, $relation, $type = null) { $class = get_class($model); $instance = new static( is_null($type) ? "Call to undefined relationship [{$relation}] on model [{$class}]." : "Call to undefined relationship [{$relation}] on model [{$class}] of type [{$type}].", ); $instance->model = $class; $instance->relation = $relation; return $instance; }
Create a new exception instance. @param object $model @param string $relation @param string|null $type @return static
make
php
illuminate/database
Eloquent/RelationNotFoundException.php
https://github.com/illuminate/database/blob/master/Eloquent/RelationNotFoundException.php
MIT
public static function bootSoftDeletes() { static::addGlobalScope(new SoftDeletingScope); }
Boot the soft deleting trait for a model. @return void
bootSoftDeletes
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function initializeSoftDeletes() { if (! isset($this->casts[$this->getDeletedAtColumn()])) { $this->casts[$this->getDeletedAtColumn()] = 'datetime'; } }
Initialize the soft deleting trait for an instance. @return void
initializeSoftDeletes
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function forceDelete() { if ($this->fireModelEvent('forceDeleting') === false) { return false; } $this->forceDeleting = true; return tap($this->delete(), function ($deleted) { $this->forceDeleting = false; if ($deleted) { $this->fireModelEvent('forceDeleted', false); } }); }
Force a hard delete on a soft deleted model. @return bool|null
forceDelete
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function forceDeleteQuietly() { return static::withoutEvents(fn () => $this->forceDelete()); }
Force a hard delete on a soft deleted model without raising any events. @return bool|null
forceDeleteQuietly
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public static function forceDestroy($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->withTrashed()->whereIn($key, $ids)->get() as $model) { if ($model->forceDelete()) { $count++; } } return $count; }
Destroy the models for the given IDs. @param \Illuminate\Support\Collection|array|int|string $ids @return int
forceDestroy
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
protected function performDeleteOnModel() { if ($this->forceDeleting) { return tap($this->setKeysForSaveQuery($this->newModelQuery())->forceDelete(), function () { $this->exists = false; }); } return $this->runSoftDelete(); }
Perform the actual delete query on this model instance. @return mixed
performDeleteOnModel
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
protected function runSoftDelete() { $query = $this->setKeysForSaveQuery($this->newModelQuery()); $time = $this->freshTimestamp(); $columns = [$this->getDeletedAtColumn() => $this->fromDateTime($time)]; $this->{$this->getDeletedAtColumn()} = $time; if ($this->usesTimestamps() && ! is_null($this->getUpdatedAtColumn())) { $this->{$this->getUpdatedAtColumn()} = $time; $columns[$this->getUpdatedAtColumn()] = $this->fromDateTime($time); } $query->update($columns); $this->syncOriginalAttributes(array_keys($columns)); $this->fireModelEvent('trashed', false); }
Perform the actual delete query on this model instance. @return void
runSoftDelete
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function restore() { // If the restoring event does not return false, we will proceed with this // restore operation. Otherwise, we bail out so the developer will stop // the restore totally. We will clear the deleted timestamp and save. if ($this->fireModelEvent('restoring') === false) { return false; } $this->{$this->getDeletedAtColumn()} = null; // Once we have saved the model, we will fire the "restored" event so this // developer will do anything they need to after a restore operation is // totally finished. Then we will return the result of the save call. $this->exists = true; $result = $this->save(); $this->fireModelEvent('restored', false); return $result; }
Restore a soft-deleted model instance. @return bool
restore
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function restoreQuietly() { return static::withoutEvents(fn () => $this->restore()); }
Restore a soft-deleted model instance without raising any events. @return bool
restoreQuietly
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function trashed() { return ! is_null($this->{$this->getDeletedAtColumn()}); }
Determine if the model instance has been soft-deleted. @return bool
trashed
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public static function softDeleted($callback) { static::registerModelEvent('trashed', $callback); }
Register a "softDeleted" model event callback with the dispatcher. @param \Illuminate\Events\QueuedClosure|callable|class-string $callback @return void
softDeleted
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public static function restoring($callback) { static::registerModelEvent('restoring', $callback); }
Register a "restoring" model event callback with the dispatcher. @param \Illuminate\Events\QueuedClosure|callable|class-string $callback @return void
restoring
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public static function restored($callback) { static::registerModelEvent('restored', $callback); }
Register a "restored" model event callback with the dispatcher. @param \Illuminate\Events\QueuedClosure|callable|class-string $callback @return void
restored
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public static function forceDeleting($callback) { static::registerModelEvent('forceDeleting', $callback); }
Register a "forceDeleting" model event callback with the dispatcher. @param \Illuminate\Events\QueuedClosure|callable|class-string $callback @return void
forceDeleting
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public static function forceDeleted($callback) { static::registerModelEvent('forceDeleted', $callback); }
Register a "forceDeleted" model event callback with the dispatcher. @param \Illuminate\Events\QueuedClosure|callable|class-string $callback @return void
forceDeleted
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function isForceDeleting() { return $this->forceDeleting; }
Determine if the model is currently force deleting. @return bool
isForceDeleting
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function getDeletedAtColumn() { return defined(static::class.'::DELETED_AT') ? static::DELETED_AT : 'deleted_at'; }
Get the name of the "deleted at" column. @return string
getDeletedAtColumn
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function getQualifiedDeletedAtColumn() { return $this->qualifyColumn($this->getDeletedAtColumn()); }
Get the fully qualified "deleted at" column. @return string
getQualifiedDeletedAtColumn
php
illuminate/database
Eloquent/SoftDeletes.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletes.php
MIT
public function apply(Builder $builder, Model $model) { $builder->whereNull($model->getQualifiedDeletedAtColumn()); }
Apply the scope to a given Eloquent query builder. @template TModel of \Illuminate\Database\Eloquent\Model @param \Illuminate\Database\Eloquent\Builder<TModel> $builder @param TModel $model @return void
apply
php
illuminate/database
Eloquent/SoftDeletingScope.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletingScope.php
MIT
public function extend(Builder $builder) { foreach ($this->extensions as $extension) { $this->{"add{$extension}"}($builder); } $builder->onDelete(function (Builder $builder) { $column = $this->getDeletedAtColumn($builder); return $builder->update([ $column => $builder->getModel()->freshTimestampString(), ]); }); }
Extend the query builder with the needed functions. @param \Illuminate\Database\Eloquent\Builder<*> $builder @return void
extend
php
illuminate/database
Eloquent/SoftDeletingScope.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletingScope.php
MIT
protected function getDeletedAtColumn(Builder $builder) { if (count((array) $builder->getQuery()->joins) > 0) { return $builder->getModel()->getQualifiedDeletedAtColumn(); } return $builder->getModel()->getDeletedAtColumn(); }
Get the "deleted at" column for the builder. @param \Illuminate\Database\Eloquent\Builder<*> $builder @return string
getDeletedAtColumn
php
illuminate/database
Eloquent/SoftDeletingScope.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletingScope.php
MIT
protected function addRestore(Builder $builder) { $builder->macro('restore', function (Builder $builder) { $builder->withTrashed(); return $builder->update([$builder->getModel()->getDeletedAtColumn() => null]); }); }
Add the restore extension to the builder. @param \Illuminate\Database\Eloquent\Builder<*> $builder @return void
addRestore
php
illuminate/database
Eloquent/SoftDeletingScope.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletingScope.php
MIT
protected function addRestoreOrCreate(Builder $builder) { $builder->macro('restoreOrCreate', function (Builder $builder, array $attributes = [], array $values = []) { $builder->withTrashed(); return tap($builder->firstOrCreate($attributes, $values), function ($instance) { $instance->restore(); }); }); }
Add the restore-or-create extension to the builder. @param \Illuminate\Database\Eloquent\Builder<*> $builder @return void
addRestoreOrCreate
php
illuminate/database
Eloquent/SoftDeletingScope.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletingScope.php
MIT
protected function addCreateOrRestore(Builder $builder) { $builder->macro('createOrRestore', function (Builder $builder, array $attributes = [], array $values = []) { $builder->withTrashed(); return tap($builder->createOrFirst($attributes, $values), function ($instance) { $instance->restore(); }); }); }
Add the create-or-restore extension to the builder. @param \Illuminate\Database\Eloquent\Builder<*> $builder @return void
addCreateOrRestore
php
illuminate/database
Eloquent/SoftDeletingScope.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletingScope.php
MIT
protected function addWithTrashed(Builder $builder) { $builder->macro('withTrashed', function (Builder $builder, $withTrashed = true) { if (! $withTrashed) { return $builder->withoutTrashed(); } return $builder->withoutGlobalScope($this); }); }
Add the with-trashed extension to the builder. @param \Illuminate\Database\Eloquent\Builder<*> $builder @return void
addWithTrashed
php
illuminate/database
Eloquent/SoftDeletingScope.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletingScope.php
MIT
protected function addWithoutTrashed(Builder $builder) { $builder->macro('withoutTrashed', function (Builder $builder) { $model = $builder->getModel(); $builder->withoutGlobalScope($this)->whereNull( $model->getQualifiedDeletedAtColumn() ); return $builder; }); }
Add the without-trashed extension to the builder. @param \Illuminate\Database\Eloquent\Builder<*> $builder @return void
addWithoutTrashed
php
illuminate/database
Eloquent/SoftDeletingScope.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletingScope.php
MIT
protected function addOnlyTrashed(Builder $builder) { $builder->macro('onlyTrashed', function (Builder $builder) { $model = $builder->getModel(); $builder->withoutGlobalScope($this)->whereNotNull( $model->getQualifiedDeletedAtColumn() ); return $builder; }); }
Add the only-trashed extension to the builder. @param \Illuminate\Database\Eloquent\Builder<*> $builder @return void
addOnlyTrashed
php
illuminate/database
Eloquent/SoftDeletingScope.php
https://github.com/illuminate/database/blob/master/Eloquent/SoftDeletingScope.php
MIT
public function collect() { return new Collection($this->getArrayCopy()); }
Get a collection containing the underlying array. @return \Illuminate\Support\Collection
collect
php
illuminate/database
Eloquent/Casts/ArrayObject.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/ArrayObject.php
MIT
public function toArray() { return $this->getArrayCopy(); }
Get the instance as an array. @return array
toArray
php
illuminate/database
Eloquent/Casts/ArrayObject.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/ArrayObject.php
MIT
public function jsonSerialize(): array { return $this->getArrayCopy(); }
Get the array that should be JSON serialized. @return array
jsonSerialize
php
illuminate/database
Eloquent/Casts/ArrayObject.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/ArrayObject.php
MIT
public static function castUsing(array $arguments) { return new class implements CastsAttributes { public function get($model, $key, $value, $attributes) { if (! isset($attributes[$key])) { return; } $data = Json::decode($attributes[$key]); return is_array($data) ? new ArrayObject($data, ArrayObject::ARRAY_AS_PROPS) : null; } public function set($model, $key, $value, $attributes) { return [$key => Json::encode($value)]; } public function serialize($model, string $key, $value, array $attributes) { return $value->getArrayCopy(); } }; }
Get the caster class to use when casting from / to this cast target. @param array $arguments @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Database\Eloquent\Casts\ArrayObject<array-key, mixed>, iterable>
castUsing
php
illuminate/database
Eloquent/Casts/AsArrayObject.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsArrayObject.php
MIT
public static function castUsing(array $arguments) { return new class($arguments) implements CastsAttributes { public function __construct(protected array $arguments) { $this->arguments = array_pad(array_values($this->arguments), 2, ''); } public function get($model, $key, $value, $attributes) { if (! isset($attributes[$key])) { return; } $data = Json::decode($attributes[$key]); $collectionClass = empty($this->arguments[0]) ? Collection::class : $this->arguments[0]; if (! is_a($collectionClass, Collection::class, true)) { throw new InvalidArgumentException('The provided class must extend ['.Collection::class.'].'); } if (! is_array($data)) { return null; } $instance = new $collectionClass($data); if (! isset($this->arguments[1]) || ! $this->arguments[1]) { return $instance; } if (is_string($this->arguments[1])) { $this->arguments[1] = Str::parseCallback($this->arguments[1]); } return is_callable($this->arguments[1]) ? $instance->map($this->arguments[1]) : $instance->mapInto($this->arguments[1][0]); } public function set($model, $key, $value, $attributes) { return [$key => Json::encode($value)]; } }; }
Get the caster class to use when casting from / to this cast target. @param array $arguments @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\Collection<array-key, mixed>, iterable>
castUsing
php
illuminate/database
Eloquent/Casts/AsCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsCollection.php
MIT
public static function of($map) { return static::using('', $map); }
Specify the type of object each item in the collection should be mapped to. @param array{class-string, string}|class-string $map @return string
of
php
illuminate/database
Eloquent/Casts/AsCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsCollection.php
MIT
public static function using($class, $map = null) { if (is_array($map) && is_callable($map)) { $map = $map[0].'@'.$map[1]; } return static::class.':'.implode(',', [$class, $map]); }
Specify the collection type for the cast. @param class-string $class @param array{class-string, string}|class-string $map @return string
using
php
illuminate/database
Eloquent/Casts/AsCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsCollection.php
MIT
public static function castUsing(array $arguments) { return new class implements CastsAttributes { public function get($model, $key, $value, $attributes) { if (isset($attributes[$key])) { return new ArrayObject(Json::decode(Crypt::decryptString($attributes[$key]))); } return null; } public function set($model, $key, $value, $attributes) { if (! is_null($value)) { return [$key => Crypt::encryptString(Json::encode($value))]; } return null; } public function serialize($model, string $key, $value, array $attributes) { return ! is_null($value) ? $value->getArrayCopy() : null; } }; }
Get the caster class to use when casting from / to this cast target. @param array $arguments @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Database\Eloquent\Casts\ArrayObject<array-key, mixed>, iterable>
castUsing
php
illuminate/database
Eloquent/Casts/AsEncryptedArrayObject.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsEncryptedArrayObject.php
MIT
public static function castUsing(array $arguments) { return new class($arguments) implements CastsAttributes { public function __construct(protected array $arguments) { $this->arguments = array_pad(array_values($this->arguments), 2, ''); } public function get($model, $key, $value, $attributes) { $collectionClass = empty($this->arguments[0]) ? Collection::class : $this->arguments[0]; if (! is_a($collectionClass, Collection::class, true)) { throw new InvalidArgumentException('The provided class must extend ['.Collection::class.'].'); } if (! isset($attributes[$key])) { return null; } $instance = new $collectionClass(Json::decode(Crypt::decryptString($attributes[$key]))); if (! isset($this->arguments[1]) || ! $this->arguments[1]) { return $instance; } if (is_string($this->arguments[1])) { $this->arguments[1] = Str::parseCallback($this->arguments[1]); } return is_callable($this->arguments[1]) ? $instance->map($this->arguments[1]) : $instance->mapInto($this->arguments[1][0]); } public function set($model, $key, $value, $attributes) { if (! is_null($value)) { return [$key => Crypt::encryptString(Json::encode($value))]; } return null; } }; }
Get the caster class to use when casting from / to this cast target. @param array $arguments @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\Collection<array-key, mixed>, iterable>
castUsing
php
illuminate/database
Eloquent/Casts/AsEncryptedCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsEncryptedCollection.php
MIT
public static function of($map) { return static::using('', $map); }
Specify the type of object each item in the collection should be mapped to. @param array{class-string, string}|class-string $map @return string
of
php
illuminate/database
Eloquent/Casts/AsEncryptedCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsEncryptedCollection.php
MIT
public static function using($class, $map = null) { if (is_array($map) && is_callable($map)) { $map = $map[0].'@'.$map[1]; } return static::class.':'.implode(',', [$class, $map]); }
Specify the collection for the cast. @param class-string $class @param array{class-string, string}|class-string $map @return string
using
php
illuminate/database
Eloquent/Casts/AsEncryptedCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsEncryptedCollection.php
MIT
public static function castUsing(array $arguments) { return new class($arguments) implements CastsAttributes { protected $arguments; public function __construct(array $arguments) { $this->arguments = $arguments; } public function get($model, $key, $value, $attributes) { if (! isset($attributes[$key])) { return; } $data = Json::decode($attributes[$key]); if (! is_array($data)) { return; } $enumClass = $this->arguments[0]; return new ArrayObject((new Collection($data))->map(function ($value) use ($enumClass) { return is_subclass_of($enumClass, BackedEnum::class) ? $enumClass::from($value) : constant($enumClass.'::'.$value); })->toArray()); } public function set($model, $key, $value, $attributes) { if ($value === null) { return [$key => null]; } $storable = []; foreach ($value as $enum) { $storable[] = $this->getStorableEnumValue($enum); } return [$key => Json::encode($storable)]; } public function serialize($model, string $key, $value, array $attributes) { return (new Collection($value->getArrayCopy()))->map(function ($enum) { return $this->getStorableEnumValue($enum); })->toArray(); } protected function getStorableEnumValue($enum) { if (is_string($enum) || is_int($enum)) { return $enum; } return enum_value($enum); } }; }
Get the caster class to use when casting from / to this cast target. @template TEnum of \UnitEnum @param array{class-string<TEnum>} $arguments @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Database\Eloquent\Casts\ArrayObject<array-key, TEnum>, iterable<TEnum>>
castUsing
php
illuminate/database
Eloquent/Casts/AsEnumArrayObject.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsEnumArrayObject.php
MIT
public static function of($class) { return static::class.':'.$class; }
Specify the Enum for the cast. @param class-string $class @return string
of
php
illuminate/database
Eloquent/Casts/AsEnumArrayObject.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsEnumArrayObject.php
MIT
public static function castUsing(array $arguments) { return new class($arguments) implements CastsAttributes { protected $arguments; public function __construct(array $arguments) { $this->arguments = $arguments; } public function get($model, $key, $value, $attributes) { if (! isset($attributes[$key])) { return; } $data = Json::decode($attributes[$key]); if (! is_array($data)) { return; } $enumClass = $this->arguments[0]; return (new Collection($data))->map(function ($value) use ($enumClass) { return is_subclass_of($enumClass, BackedEnum::class) ? $enumClass::from($value) : constant($enumClass.'::'.$value); }); } public function set($model, $key, $value, $attributes) { $value = $value !== null ? Json::encode((new Collection($value))->map(function ($enum) { return $this->getStorableEnumValue($enum); })->jsonSerialize()) : null; return [$key => $value]; } public function serialize($model, string $key, $value, array $attributes) { return (new Collection($value))->map(function ($enum) { return $this->getStorableEnumValue($enum); })->toArray(); } protected function getStorableEnumValue($enum) { if (is_string($enum) || is_int($enum)) { return $enum; } return enum_value($enum); } }; }
Get the caster class to use when casting from / to this cast target. @template TEnum of \UnitEnum @param array{class-string<TEnum>} $arguments @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\Collection<array-key, TEnum>, iterable<TEnum>>
castUsing
php
illuminate/database
Eloquent/Casts/AsEnumCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsEnumCollection.php
MIT
public static function of($class) { return static::class.':'.$class; }
Specify the Enum for the cast. @param class-string $class @return string
of
php
illuminate/database
Eloquent/Casts/AsEnumCollection.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsEnumCollection.php
MIT
public static function castUsing(array $arguments) { return new class implements CastsAttributes { public function get($model, $key, $value, $attributes) { return isset($value) ? new HtmlString($value) : null; } public function set($model, $key, $value, $attributes) { return isset($value) ? (string) $value : null; } }; }
Get the caster class to use when casting from / to this cast target. @param array $arguments @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\HtmlString, string|HtmlString>
castUsing
php
illuminate/database
Eloquent/Casts/AsHtmlString.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsHtmlString.php
MIT
public static function castUsing(array $arguments) { return new class implements CastsAttributes { public function get($model, $key, $value, $attributes) { return isset($value) ? new Stringable($value) : null; } public function set($model, $key, $value, $attributes) { return isset($value) ? (string) $value : null; } }; }
Get the caster class to use when casting from / to this cast target. @param array $arguments @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\Stringable, string|\Stringable>
castUsing
php
illuminate/database
Eloquent/Casts/AsStringable.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsStringable.php
MIT
public static function castUsing(array $arguments) { return new class implements CastsAttributes { public function get($model, $key, $value, $attributes) { return isset($value) ? new Uri($value) : null; } public function set($model, $key, $value, $attributes) { return isset($value) ? (string) $value : null; } }; }
Get the caster class to use when casting from / to this cast target. @param array $arguments @return \Illuminate\Contracts\Database\Eloquent\CastsAttributes<\Illuminate\Support\Uri, string|Uri>
castUsing
php
illuminate/database
Eloquent/Casts/AsUri.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/AsUri.php
MIT
public function __construct(?callable $get = null, ?callable $set = null) { $this->get = $get; $this->set = $set; }
Create a new attribute accessor / mutator. @param callable|null $get @param callable|null $set
__construct
php
illuminate/database
Eloquent/Casts/Attribute.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/Attribute.php
MIT
public static function make(?callable $get = null, ?callable $set = null): static { return new static($get, $set); }
Create a new attribute accessor / mutator. @param callable|null $get @param callable|null $set @return static
make
php
illuminate/database
Eloquent/Casts/Attribute.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/Attribute.php
MIT
public static function get(callable $get) { return new static($get); }
Create a new attribute accessor. @param callable $get @return static
get
php
illuminate/database
Eloquent/Casts/Attribute.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/Attribute.php
MIT
public static function set(callable $set) { return new static(null, $set); }
Create a new attribute mutator. @param callable $set @return static
set
php
illuminate/database
Eloquent/Casts/Attribute.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/Attribute.php
MIT
public function withoutObjectCaching() { $this->withObjectCaching = false; return $this; }
Disable object caching for the attribute. @return static
withoutObjectCaching
php
illuminate/database
Eloquent/Casts/Attribute.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/Attribute.php
MIT
public function shouldCache() { $this->withCaching = true; return $this; }
Enable caching for the attribute. @return static
shouldCache
php
illuminate/database
Eloquent/Casts/Attribute.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/Attribute.php
MIT
public static function encodeUsing(?callable $encoder): void { static::$encoder = $encoder; }
Encode all values using the given callable.
encodeUsing
php
illuminate/database
Eloquent/Casts/Json.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/Json.php
MIT
public static function decodeUsing(?callable $decoder): void { static::$decoder = $decoder; }
Decode all values using the given callable.
decodeUsing
php
illuminate/database
Eloquent/Casts/Json.php
https://github.com/illuminate/database/blob/master/Eloquent/Casts/Json.php
MIT
public function getFillable() { return $this->fillable; }
Get the fillable attributes for the model. @return array<string>
getFillable
php
illuminate/database
Eloquent/Concerns/GuardsAttributes.php
https://github.com/illuminate/database/blob/master/Eloquent/Concerns/GuardsAttributes.php
MIT
public function fillable(array $fillable) { $this->fillable = $fillable; return $this; }
Set the fillable attributes for the model. @param array<string> $fillable @return $this
fillable
php
illuminate/database
Eloquent/Concerns/GuardsAttributes.php
https://github.com/illuminate/database/blob/master/Eloquent/Concerns/GuardsAttributes.php
MIT
public function mergeFillable(array $fillable) { $this->fillable = array_values(array_unique(array_merge($this->fillable, $fillable))); return $this; }
Merge new fillable attributes with existing fillable attributes on the model. @param array<string> $fillable @return $this
mergeFillable
php
illuminate/database
Eloquent/Concerns/GuardsAttributes.php
https://github.com/illuminate/database/blob/master/Eloquent/Concerns/GuardsAttributes.php
MIT
public function getGuarded() { return $this->guarded === false ? [] : $this->guarded; }
Get the guarded attributes for the model. @return array<string>
getGuarded
php
illuminate/database
Eloquent/Concerns/GuardsAttributes.php
https://github.com/illuminate/database/blob/master/Eloquent/Concerns/GuardsAttributes.php
MIT
public function guard(array $guarded) { $this->guarded = $guarded; return $this; }
Set the guarded attributes for the model. @param array<string> $guarded @return $this
guard
php
illuminate/database
Eloquent/Concerns/GuardsAttributes.php
https://github.com/illuminate/database/blob/master/Eloquent/Concerns/GuardsAttributes.php
MIT
public function mergeGuarded(array $guarded) { $this->guarded = array_values(array_unique(array_merge($this->guarded, $guarded))); return $this; }
Merge new guarded attributes with existing guarded attributes on the model. @param array<string> $guarded @return $this
mergeGuarded
php
illuminate/database
Eloquent/Concerns/GuardsAttributes.php
https://github.com/illuminate/database/blob/master/Eloquent/Concerns/GuardsAttributes.php
MIT
public static function unguard($state = true) { static::$unguarded = $state; }
Disable all mass assignable restrictions. @param bool $state @return void
unguard
php
illuminate/database
Eloquent/Concerns/GuardsAttributes.php
https://github.com/illuminate/database/blob/master/Eloquent/Concerns/GuardsAttributes.php
MIT