From be59602b30fa35f0d2cf94df507dc51eed1c84e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurice=20Preu=C3=9F?= Date: Sun, 1 Nov 2026 12:55:51 +0100 Subject: [PATCH] Declare the billable's API caches, so Eloquent models can still be saved The caches were undeclared properties: on an Eloquent model they went through Model::__set into the attributes, and save() failed with "no such column: ordersCache". Co-Authored-By: Claude Opus 5.5 --- src/Id/Billable.php | 15 +++++++++++++++ tests/Id/BillableModelTest.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/Id/BillableModelTest.php diff --git a/src/Id/Billable.php b/src/Id/Billable.php index 81b4737..511d9e9 100644 --- a/src/Id/Billable.php +++ b/src/Id/Billable.php @@ -29,6 +29,21 @@ trait Billable use ManagesTransactions; use ManagesUserSshKeys; + /* + * API results cached per instance. Declared, so Eloquent models don't take them for + * attributes (an undeclared property goes through Model::__set and save() then fails + * with "no such column"). + */ + protected mixed $addressesCache = null; + protected mixed $countriesCache = null; + protected mixed $defaultPaymentMethodCache = null; + protected mixed $invoicesCache = null; + protected mixed $ordersCache = null; + protected mixed $paymentMethodsCache = null; + protected mixed $subscriptionsCache = null; + protected mixed $transactionsCache = null; + protected mixed $userDataCache = null; + /** * Get the currently authenticated user. * diff --git a/tests/Id/BillableModelTest.php b/tests/Id/BillableModelTest.php new file mode 100644 index 0000000..c7d8c3a --- /dev/null +++ b/tests/Id/BillableModelTest.php @@ -0,0 +1,31 @@ +{$name.'Cache'} = 'cached'; + } + } + }; + $user->email = 'ada@example.com'; + + $user->cacheAll(); + + // save() would otherwise write them as columns ("no such column: ordersCache") + $this->assertSame(['email' => 'ada@example.com'], $user->getAttributes()); + } +}