| 123456789101112131415161718192021222324 |
- <?php
- namespace App\Casts;
- use App\ValueObjects\Cnpj;
- use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
- use Illuminate\Database\Eloquent\Model;
- class CnpjCast implements CastsAttributes
- {
- public function get(Model $model, string $key, mixed $value, array $attributes): ?Cnpj
- {
- return $value === null ? null : new Cnpj((string) $value);
- }
- public function set(Model $model, string $key, mixed $value, array $attributes): ?string
- {
- if ($value === null) {
- return null;
- }
- return ($value instanceof Cnpj ? $value : new Cnpj((string) $value))->value();
- }
- }
|