From 2ce9893e81d540aec9ed255f13f6334e7bfe74d2 Mon Sep 17 00:00:00 2001 From: "Fabian @ Blax Software" Date: Sat, 28 Feb 2026 13:05:01 +0100 Subject: [PATCH] BF has access --- src/Traits/HasAccess.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Traits/HasAccess.php b/src/Traits/HasAccess.php index 683efdd..950c68c 100644 --- a/src/Traits/HasAccess.php +++ b/src/Traits/HasAccess.php @@ -78,16 +78,20 @@ trait HasAccess /** * Grant this entity access to a specific model. * + * Uses updateOrCreate so that re-granting access (e.g., after a renewal + * purchase) refreshes the expires_at and context even when an existing + * (possibly expired) record already exists. + * * @param Model $accessible The target model * @param array|null $context Optional JSON context * @param Carbon|null $expiresAt Optional expiration - * @return Model The created or existing Access entry + * @return Model The created or updated Access entry */ public function grantAccess(Model $accessible, ?array $context = null, ?Carbon $expiresAt = null): Model { $accessModel = config('roles.models.access'); - return $accessModel::firstOrCreate([ + return $accessModel::updateOrCreate([ 'entity_type' => $this->getMorphClass(), 'entity_id' => $this->getKey(), 'accessible_type' => $accessible->getMorphClass(),