From a3161888aa175f8a491464c1cbd6f8b50176c3b2 Mon Sep 17 00:00:00 2001 From: Joel Male Date: Mon, 23 Mar 2026 16:28:53 +1000 Subject: [PATCH] chore: bump to v2.0.0 with PHP 8.3+ support and invalid item cleanup --- .github/workflows/tests.yml | 2 +- composer.json | 14 +++++++------- src/Cart.php | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index aad83e8..bc32d7c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,7 +13,7 @@ jobs: strategy: fail-fast: true matrix: - php: ['8.2', '8.3', '8.4'] + php: ['8.3', '8.4', '8.5'] stability: [prefer-stable] steps: diff --git a/composer.json b/composer.json index 529de6c..6e4252f 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "joelwmale/laravel-cart", - "version": "1.2.1", + "version": "2.0.0", "description": "A cart implementation for Laravel", "keywords": [ "laravel", @@ -19,12 +19,12 @@ } ], "require": { - "php": ">=8.2", - "illuminate/support": "^10.0|^11.0|^12.0", - "illuminate/auth": "^10.0|^11.0|^12.0", - "illuminate/container": "^10.0|^11.0|^12.0", - "illuminate/database": "^10.0|^11.0|^12.0", - "illuminate/validation": "^10.0|^11.0|^12.0" + "php": ">=8.3", + "illuminate/support": "^11.0|^12.0|^13.0", + "illuminate/auth": "^11.0|^12.0|^13.0", + "illuminate/container": "^11.0|^12.0|^13.0", + "illuminate/database": "^11.0|^12.0|^13.0", + "illuminate/validation": "^11.0|^12.0|^13.0" }, "require-dev": { "mockery/mockery": "^1.6", diff --git a/src/Cart.php b/src/Cart.php index a0865a3..b1949cd 100644 --- a/src/Cart.php +++ b/src/Cart.php @@ -165,9 +165,31 @@ public function add( $this->currentItemId = $id; + // clean up any incomplete items + $this->removeInvalidItems(); + return $this; } + /** + * Remove any incomplete items + */ + public function removeInvalidItems(): bool + { + $carts = $this->getContent(); + + foreach ($carts as $index => $cart) { + + if (! (isset($cart['id'], $cart['name'], $cart['quantity']))) { + + // remove item + $this->remove($index); + } + } + + return true; + } + /** * Update a cart item with whatever data is passed in */