diff --git a/src/Casts/HtmlDateTimeCast.php b/src/Casts/HtmlDateTimeCast.php deleted file mode 100644 index 7e219aa..0000000 --- a/src/Casts/HtmlDateTimeCast.php +++ /dev/null @@ -1,70 +0,0 @@ -created_at->format('Y-m-d\TH:i') - */ -class HtmlDateTimeCast implements CastsAttributes -{ - /** - * Cast the given value. - * - * @param array $attributes - */ - public function get(Model $model, string $key, mixed $value, array $attributes): ?Carbon - { - if ($value === null) { - return null; - } - - // Handle datetime strings from database - return Carbon::parse($value); - } - - /** - * Prepare the given value for storage. - * - * @param array $attributes - */ - public function set(Model $model, string $key, mixed $value, array $attributes): ?string - { - if ($value === null) { - return null; - } - - // Handle Carbon instances - if ($value instanceof Carbon) { - return $value->format('Y-m-d H:i:s'); - } - - // Handle DateTimeInterface - if ($value instanceof \DateTimeInterface) { - return Carbon::instance($value)->format('Y-m-d H:i:s'); - } - - // Handle string input (including HTML5 datetime-local format) - if (is_string($value)) { - return Carbon::parse($value)->format('Y-m-d H:i:s'); - } - - // Handle numeric timestamp (Unix timestamp) - if (is_numeric($value)) { - return Carbon::createFromTimestamp($value)->format('Y-m-d H:i:s'); - } - - throw new \InvalidArgumentException( - "Invalid datetime value for {$key}. Expected string, DateTimeInterface, Carbon, or timestamp." - ); - } -} diff --git a/src/Models/Cart.php b/src/Models/Cart.php index bfcb9db..ffaa349 100644 --- a/src/Models/Cart.php +++ b/src/Models/Cart.php @@ -2,7 +2,6 @@ namespace Blax\Shop\Models; -use Blax\Shop\Casts\HtmlDateTimeCast; use Blax\Shop\Contracts\Cartable; use Blax\Shop\Enums\CartStatus; use Blax\Shop\Enums\ProductType; @@ -41,8 +40,8 @@ class Cart extends Model 'converted_at' => 'datetime', 'last_activity_at' => 'datetime', 'meta' => 'object', - 'from_date' => HtmlDateTimeCast::class, - 'until_date' => HtmlDateTimeCast::class, + 'from_date' => 'datetime', + 'until_date' => 'datetime', ]; protected $appends = [ diff --git a/src/Models/CartItem.php b/src/Models/CartItem.php index d9c0b74..669f8e5 100644 --- a/src/Models/CartItem.php +++ b/src/Models/CartItem.php @@ -2,7 +2,6 @@ namespace Blax\Shop\Models; -use Blax\Shop\Casts\HtmlDateTimeCast; use Blax\Shop\Exceptions\InvalidDateRangeException; use Blax\Workkit\Traits\HasMeta; use Illuminate\Database\Eloquent\Concerns\HasUuids; @@ -36,8 +35,8 @@ class CartItem extends Model 'subtotal' => 'decimal:2', 'parameters' => 'array', 'meta' => 'array', - 'from' => HtmlDateTimeCast::class, - 'until' => HtmlDateTimeCast::class, + 'from' => 'datetime', + 'until' => 'datetime', ]; protected $appends = [