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