27 lines
616 B
PHP
27 lines
616 B
PHP
<?php
|
|
|
|
namespace Zoomyboy\LaravelNami\Casters;
|
|
|
|
use DateTimeInterface;
|
|
use Spatie\LaravelData\Casts\Cast;
|
|
use Spatie\LaravelData\Casts\Uncastable;
|
|
use Spatie\LaravelData\Support\Creation\CreationContext;
|
|
use Spatie\LaravelData\Support\DataProperty;
|
|
|
|
class NullValueCast implements Cast
|
|
{
|
|
public function __construct(
|
|
private int $id
|
|
) {
|
|
}
|
|
|
|
public function cast(DataProperty $property, mixed $value, array $properties, CreationContext $context): DateTimeInterface|Uncastable|null|int
|
|
{
|
|
if ($this->id === $value) {
|
|
return null;
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
}
|