Skip to content

[12.x] add generics to Model attribute related methods and properties #55962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ public function totallyGuarded()
/**
* Get the fillable attributes of a given array.
*
* @param array $attributes
* @return array
* @param array<string, mixed> $attributes
* @return array<string, mixed>
*/
protected function fillableFromArray(array $attributes)
{
Expand Down
56 changes: 28 additions & 28 deletions src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ trait HasAttributes
/**
* The model's attributes.
*
* @var array
* @var array<string, mixed>
*/
protected $attributes = [];

/**
* The model attribute's original state.
*
* @var array
* @var array<string, mixed>
*/
protected $original = [];

/**
* The changed model attributes.
*
* @var array
* @var array<string, mixed>
*/
protected $changes = [];

/**
* The previous state of the changed model attributes.
*
* @var array
* @var array<string, mixed>
*/
protected $previous = [];

Expand Down Expand Up @@ -209,7 +209,7 @@ protected function initializeHasAttributes()
/**
* Convert the model's attributes to an array.
*
* @return array
* @return array<string, mixed>
*/
public function attributesToArray()
{
Expand Down Expand Up @@ -244,8 +244,8 @@ public function attributesToArray()
/**
* Add the date attributes to the attributes array.
*
* @param array $attributes
* @return array
* @param array<string, mixed> $attributes
* @return array<string, mixed>
*/
protected function addDateAttributesToArray(array $attributes)
{
Expand All @@ -265,9 +265,9 @@ protected function addDateAttributesToArray(array $attributes)
/**
* Add the mutated attributes to the attributes array.
*
* @param array $attributes
* @param array $mutatedAttributes
* @return array
* @param array<string, mixed> $attributes
* @param array<string, mixed> $mutatedAttributes
* @return array<string, mixed>
*/
protected function addMutatedAttributesToArray(array $attributes, array $mutatedAttributes)
{
Expand All @@ -293,9 +293,9 @@ protected function addMutatedAttributesToArray(array $attributes, array $mutated
/**
* Add the casted attributes to the attributes array.
*
* @param array $attributes
* @param array $mutatedAttributes
* @return array
* @param array<string, mixed> $attributes
* @param array<string, mixed> $mutatedAttributes
* @return array<string, mixed>
*/
protected function addCastAttributesToArray(array $attributes, array $mutatedAttributes)
{
Expand Down Expand Up @@ -348,7 +348,7 @@ protected function addCastAttributesToArray(array $attributes, array $mutatedAtt
/**
* Get an attribute array of all arrayable attributes.
*
* @return array
* @return array<string, mixed>
*/
protected function getArrayableAttributes()
{
Expand Down Expand Up @@ -2032,8 +2032,8 @@ public function getRawOriginal($key = null, $default = null)
/**
* Get a subset of the model's attributes.
*
* @param array|mixed $attributes
* @return array
* @param array<string>|mixed $attributes
* @return array<string, mixed>
*/
public function only($attributes)
{
Expand All @@ -2049,7 +2049,7 @@ public function only($attributes)
/**
* Get all attributes except the given ones.
*
* @param array|mixed $attributes
* @param array<string>|mixed $attributes
* @return array
*/
public function except($attributes)
Expand Down Expand Up @@ -2093,7 +2093,7 @@ public function syncOriginalAttribute($attribute)
/**
* Sync multiple original attribute with their current values.
*
* @param array|string $attributes
* @param array<string>|string $attributes
* @return $this
*/
public function syncOriginalAttributes($attributes)
Expand Down Expand Up @@ -2125,7 +2125,7 @@ public function syncChanges()
/**
* Determine if the model or any of the given attribute(s) have been modified.
*
* @param array|string|null $attributes
* @param array<string>|string|null $attributes
* @return bool
*/
public function isDirty($attributes = null)
Expand All @@ -2138,7 +2138,7 @@ public function isDirty($attributes = null)
/**
* Determine if the model or all the given attribute(s) have remained the same.
*
* @param array|string|null $attributes
* @param array<string>|string|null $attributes
* @return bool
*/
public function isClean($attributes = null)
Expand All @@ -2161,7 +2161,7 @@ public function discardChanges()
/**
* Determine if the model or any of the given attribute(s) were changed when the model was last saved.
*
* @param array|string|null $attributes
* @param array<string>|string|null $attributes
* @return bool
*/
public function wasChanged($attributes = null)
Expand All @@ -2174,8 +2174,8 @@ public function wasChanged($attributes = null)
/**
* Determine if any of the given attributes were changed when the model was last saved.
*
* @param array $changes
* @param array|string|null $attributes
* @param array<string> $changes
* @param array<string>|string|null $attributes
* @return bool
*/
protected function hasChanges($changes, $attributes = null)
Expand All @@ -2202,7 +2202,7 @@ protected function hasChanges($changes, $attributes = null)
/**
* Get the attributes that have been changed since the last sync.
*
* @return array
* @return array<string, mixed>
*/
public function getDirty()
{
Expand All @@ -2220,7 +2220,7 @@ public function getDirty()
/**
* Get the attributes that have been changed since the last sync for an update operation.
*
* @return array
* @return array<string, mixed>
*/
protected function getDirtyForUpdate()
{
Expand All @@ -2230,7 +2230,7 @@ protected function getDirtyForUpdate()
/**
* Get the attributes that were changed when the model was last saved.
*
* @return array
* @return array<string, mixed>
*/
public function getChanges()
{
Expand All @@ -2240,7 +2240,7 @@ public function getChanges()
/**
* Get the attributes that were previously original before the model was last saved.
*
* @return array
* @return array<string, mixed>
*/
public function getPrevious()
{
Expand Down Expand Up @@ -2347,7 +2347,7 @@ protected function transformModelValue($key, $value)
/**
* Append attributes to query when building a query.
*
* @param array|string $attributes
* @param array<string>|string $attributes
* @return $this
*/
public function append($attributes)
Expand Down
26 changes: 13 additions & 13 deletions src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ abstract class Model implements Arrayable, ArrayAccess, CanBeEscapedWhenCastToSt
/**
* Create a new Eloquent model instance.
*
* @param array $attributes
* @param array<string, mixed> $attributes
*/
public function __construct(array $attributes = [])
{
Expand Down Expand Up @@ -568,7 +568,7 @@ public static function withoutBroadcasting(callable $callback)
/**
* Fill the model with an array of attributes.
*
* @param array $attributes
* @param array<string, mixed> $attributes
* @return $this
*
* @throws \Illuminate\Database\Eloquent\MassAssignmentException
Expand Down Expand Up @@ -618,7 +618,7 @@ public function fill(array $attributes)
/**
* Fill the model with an array of attributes. Force mass assignment.
*
* @param array $attributes
* @param array<string, mixed> $attributes
* @return $this
*/
public function forceFill(array $attributes)
Expand Down Expand Up @@ -657,7 +657,7 @@ public function qualifyColumns($columns)
/**
* Create a new instance of the given model.
*
* @param array $attributes
* @param array<string, mixed> $attributes
* @param bool $exists
* @return static
*/
Expand Down Expand Up @@ -686,7 +686,7 @@ public function newInstance($attributes = [], $exists = false)
/**
* Create a new model instance that is existing.
*
* @param array $attributes
* @param array<string, mixed> $attributes
* @param string|null $connection
* @return static
*/
Expand Down Expand Up @@ -1049,8 +1049,8 @@ protected function incrementOrDecrement($column, $amount, $extra, $method)
/**
* Update the model in the database.
*
* @param array $attributes
* @param array $options
* @param array<string, mixed> $attributes
* @param array<string, mixed> $options
* @return bool
*/
public function update(array $attributes = [], array $options = [])
Expand All @@ -1065,8 +1065,8 @@ public function update(array $attributes = [], array $options = [])
/**
* Update the model in the database within a transaction.
*
* @param array $attributes
* @param array $options
* @param array<string, mixed> $attributes
* @param array<string, mixed> $options
* @return bool
*
* @throws \Throwable
Expand All @@ -1083,8 +1083,8 @@ public function updateOrFail(array $attributes = [], array $options = [])
/**
* Update the model in the database without raising any events.
*
* @param array $attributes
* @param array $options
* @param array<string, mixed> $attributes
* @param array<string, mixed> $options
* @return bool
*/
public function updateQuietly(array $attributes = [], array $options = [])
Expand Down Expand Up @@ -1400,7 +1400,7 @@ protected function performInsert(Builder $query)
* Insert the given attributes and set the ID on the model.
*
* @param \Illuminate\Database\Eloquent\Builder<static> $query
* @param array $attributes
* @param array<string, mixed> $attributes
* @return void
*/
protected function insertAndSetId(Builder $query, $attributes)
Expand Down Expand Up @@ -1668,7 +1668,7 @@ protected function newBaseQueryBuilder()
* Create a new pivot model instance.
*
* @param \Illuminate\Database\Eloquent\Model $parent
* @param array $attributes
* @param array<string, mixed> $attributes
* @param string $table
* @param bool $exists
* @param string|null $using
Expand Down