Add support for CastsInboundAttributes (#1329)

* Add support for CastsInboundAttributes

* Update changelog

Co-authored-by: Simon Verwaard <[email protected]>
This commit is contained in:
sforward
2022-09-13 10:42:06 +02:00
committed by GitHub
co-authored by Simon Verwaard
parent e8ecb3da88
commit dda200fd34
5 changed files with 32 additions and 0 deletions
+9
View File
@@ -22,6 +22,7 @@ use Doctrine\DBAL\Types\Type;
use Illuminate\Console\Command;
use Illuminate\Contracts\Database\Eloquent\Castable;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
use Illuminate\Contracts\Database\Eloquent\CastsInboundAttributes;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Database\Eloquent\Model;
@@ -429,6 +430,9 @@ class ModelsCommand extends Command
if (!isset($this->properties[$name])) {
continue;
}
if ($this->isInboundCast($realType)) {
continue;
}
$realType = $this->checkForCastableCasts($realType, $params);
$realType = $this->checkForCustomLaravelCasts($realType);
@@ -1295,6 +1299,11 @@ class ModelsCommand extends Command
return $keyword;
}
protected function isInboundCast(string $type): bool
{
return class_exists($type) && is_subclass_of($type, CastsInboundAttributes::class);
}
protected function checkForCastableCasts(string $type, array $params = []): string
{
if (!class_exists($type) || !interface_exists(Castable::class)) {