From a4e690998e42402be9dda49bf566f292a4497110 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 18 Oct 2024 13:51:10 +0200 Subject: [PATCH] Check if key is set (#1691) --- src/DataCollector/GateCollector.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DataCollector/GateCollector.php b/src/DataCollector/GateCollector.php index 45941362b..7842c64e1 100644 --- a/src/DataCollector/GateCollector.php +++ b/src/DataCollector/GateCollector.php @@ -64,7 +64,11 @@ public function addCheck($user, $ability, $result, $arguments = []) if (isset($arguments[0])) { if ($arguments[0] instanceof Model) { $model = $arguments[0]; - $target = get_class($model) . '(' . $model->getKeyName() .'=' . $model->getKey().')'; + if ($model->getKeyName() && $model->hasAttribute($model->getKeyName())) { + $target = get_class($model) . '(' . $model->getKeyName() . '=' . $model->getKey() . ')'; + } else { + $target = get_class($model); + } } else if (is_string($arguments[0])) { $target = $arguments[0]; }