dep: package update

This commit is contained in:
2021-11-08 16:10:01 +09:00
parent 38208750e7
commit 2c533d2ab3
783 changed files with 4581 additions and 20980 deletions
@@ -8,6 +8,8 @@ use DateTimeInterface;
use Illuminate\Contracts\Database\Eloquent\Castable;
use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes;
use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Database\Eloquent\Casts\AsArrayObject;
use Illuminate\Database\Eloquent\Casts\AsCollection;
use Illuminate\Database\Eloquent\InvalidCastException;
use Illuminate\Database\Eloquent\JsonEncodingException;
use Illuminate\Database\Eloquent\Relations\Relation;
@@ -262,6 +264,10 @@ trait HasAttributes
$attributes[$key] = $this->serializeClassCastableAttribute($key, $attributes[$key]);
}
if ($this->isEnumCastable($key)) {
$attributes[$key] = isset($attributes[$key]) ? $attributes[$key]->value : null;
}
if ($attributes[$key] instanceof Arrayable) {
$attributes[$key] = $attributes[$key]->toArray();
}
@@ -620,6 +626,10 @@ trait HasAttributes
return $this->asTimestamp($value);
}
if ($this->isEnumCastable($key)) {
return $this->getEnumCastableAttributeValue($key, $value);
}
if ($this->isClassCastable($key)) {
return $this->getClassCastableAttributeValue($key, $value);
}
@@ -655,6 +665,24 @@ trait HasAttributes
}
}
/**
* Cast the given attribute to an enum.
*
* @param string $key
* @param mixed $value
* @return mixed
*/
protected function getEnumCastableAttributeValue($key, $value)
{
if (is_null($value)) {
return;
}
$castType = $this->getCasts()[$key];
return $castType::from($value);
}
/**
* Get the type of cast for a model attribute.
*
@@ -765,6 +793,12 @@ trait HasAttributes
$value = $this->fromDateTime($value);
}
if ($this->isEnumCastable($key)) {
$this->setEnumCastableAttribute($key, $value);
return $this;
}
if ($this->isClassCastable($key)) {
$this->setClassCastableAttribute($key, $value);
@@ -883,6 +917,18 @@ trait HasAttributes
}
}
/**
* Set the value of an enum castable attribute.
*
* @param string $key
* @param \BackedEnum $value
* @return void
*/
protected function setEnumCastableAttribute($key, $value)
{
$this->attributes[$key] = isset($value) ? $value->value : null;
}
/**
* Get an array attribute with the given key and value set.
*
@@ -1217,7 +1263,18 @@ trait HasAttributes
*/
protected function isDateCastable($key)
{
return $this->hasCast($key, ['date', 'datetime', 'custom_datetime', 'immutable_date', 'immutable_datetime', 'immutable_custom_datetime']);
return $this->hasCast($key, ['date', 'datetime', 'immutable_date', 'immutable_datetime']);
}
/**
* Determine whether a value is Date / DateTime custom-castable for inbound manipulation.
*
* @param string $key
* @return bool
*/
protected function isDateCastableWithCustomFormat($key)
{
return $this->hasCast($key, ['custom_datetime', 'immutable_custom_datetime']);
}
/**
@@ -1269,6 +1326,29 @@ trait HasAttributes
throw new InvalidCastException($this->getModel(), $key, $castType);
}
/**
* Determine if the given key is cast using an enum.
*
* @param string $key
* @return bool
*/
protected function isEnumCastable($key)
{
if (! array_key_exists($key, $this->getCasts())) {
return false;
}
$castType = $this->getCasts()[$key];
if (in_array($castType, static::$primitiveCastTypes)) {
return false;
}
if (function_exists('enum_exists') && enum_exists($castType)) {
return true;
}
}
/**
* Determine if the key is deviable using a custom class.
*
@@ -1294,8 +1374,9 @@ trait HasAttributes
*/
protected function isClassSerializable($key)
{
return $this->isClassCastable($key) &&
method_exists($this->parseCasterClass($this->getCasts()[$key]), 'serialize');
return ! $this->isEnumCastable($key) &&
$this->isClassCastable($key) &&
method_exists($this->resolveCasterClass($key), 'serialize');
}
/**
@@ -1643,7 +1724,7 @@ trait HasAttributes
return true;
} elseif (is_null($attribute)) {
return false;
} elseif ($this->isDateAttribute($key) || $this->isDateCastable($key)) {
} elseif ($this->isDateAttribute($key) || $this->isDateCastableWithCustomFormat($key)) {
return $this->fromDateTime($attribute) ===
$this->fromDateTime($original);
} elseif ($this->hasCast($key, ['object', 'collection'])) {
@@ -1658,6 +1739,8 @@ trait HasAttributes
} elseif ($this->hasCast($key, static::$primitiveCastTypes)) {
return $this->castAttribute($key, $attribute) ===
$this->castAttribute($key, $original);
} elseif ($this->isClassCastable($key) && in_array($this->getCasts()[$key], [AsArrayObject::class, AsCollection::class])) {
return $this->fromJson($attribute) === $this->fromJson($original);
}
return is_numeric($attribute) && is_numeric($original)
@@ -2,8 +2,11 @@
namespace Illuminate\Database\Eloquent\Concerns;
use BadMethodCallException;
use Closure;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\RelationNotFoundException;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Database\Query\Builder as QueryBuilder;
@@ -455,6 +458,56 @@ trait QueriesRelationships
return $this->whereMorphedTo($relation, $model, 'or');
}
/**
* Add a "belongs to" relationship where clause to the query.
*
* @param \Illuminate\Database\Eloquent\Model $related
* @param string $relationship
* @param string $boolean
* @return $this
*
* @throws \Exception
*/
public function whereBelongsTo($related, $relationshipName = null, $boolean = 'and')
{
if ($relationshipName === null) {
$relationshipName = Str::camel(class_basename($related));
}
try {
$relationship = $this->model->{$relationshipName}();
} catch (BadMethodCallException $exception) {
throw RelationNotFoundException::make($this->model, $relationshipName);
}
if (! $relationship instanceof BelongsTo) {
throw RelationNotFoundException::make($this->model, $relationshipName, BelongsTo::class);
}
$this->where(
$relationship->getQualifiedForeignKeyName(),
'=',
$related->getAttributeValue($relationship->getOwnerKeyName()),
$boolean,
);
return $this;
}
/**
* Add an "BelongsTo" relationship with an "or where" clause to the query.
*
* @param \Illuminate\Database\Eloquent\Model $related
* @param string $relationship
* @return $this
*
* @throws \Exception
*/
public function orWhereBelongsTo($related, $relationshipName = null)
{
return $this->whereBelongsTo($related, $relationshipName, 'or');
}
/**
* Add subselect queries to include an aggregate value for a relationship.
*