Skip to content

Commit 7a91480

Browse files
roberthuntbarryvdh
authored andcommitted
If user is instance of Authenticatable call getAuthIdentifier() defined by the interface rather than assuming it has a public id field (#799)
1 parent 664fa43 commit 7a91480

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/DataCollector/GateCollector.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use DebugBar\DataCollector\MessagesCollector;
77
use Illuminate\Contracts\Auth\Access\Gate;
88
use Illuminate\Contracts\Auth\Access\Authorizable;
9+
use Illuminate\Contracts\Auth\Authenticatable;
910
use Symfony\Component\VarDumper\Cloner\VarCloner;
1011

1112
/**
@@ -25,12 +26,20 @@ public function __construct(Gate $gate)
2526

2627
public function addCheck(Authorizable $user = null, $ability, $result, $arguments = [])
2728
{
29+
$userKey = 'user';
30+
$userId = null;
31+
32+
if ($user) {
33+
$userKey = snake_case(class_basename($user));
34+
$userId = $user instanceof Authenticatable ? $user->getAuthIdentifier() : $user->id;
35+
}
36+
2837
$label = $result ? 'success' : 'error';
2938

3039
$this->addMessage([
3140
'ability' => $ability,
3241
'result' => $result,
33-
($user ? snake_case(class_basename($user)) : 'user') => ($user ? $user->id : null),
42+
$userKey => $userId,
3443
'arguments' => $this->getDataFormatter()->formatVar($arguments),
3544
], $label, false);
3645
}

0 commit comments

Comments
 (0)