Skip to content

Commit

Permalink
If user is instance of Authenticatable call getAuthIdentifier() defin…
Browse files Browse the repository at this point in the history
…ed by the interface rather than assuming it has a public id field (#799)
  • Loading branch information
roberthunt authored and barryvdh committed Mar 6, 2018
1 parent 664fa43 commit 7a91480
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/DataCollector/GateCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DebugBar\DataCollector\MessagesCollector;
use Illuminate\Contracts\Auth\Access\Gate;
use Illuminate\Contracts\Auth\Access\Authorizable;
use Illuminate\Contracts\Auth\Authenticatable;
use Symfony\Component\VarDumper\Cloner\VarCloner;

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

public function addCheck(Authorizable $user = null, $ability, $result, $arguments = [])
{
$userKey = 'user';
$userId = null;

if ($user) {
$userKey = snake_case(class_basename($user));
$userId = $user instanceof Authenticatable ? $user->getAuthIdentifier() : $user->id;
}

$label = $result ? 'success' : 'error';

$this->addMessage([
'ability' => $ability,
'result' => $result,
($user ? snake_case(class_basename($user)) : 'user') => ($user ? $user->id : null),
$userKey => $userId,
'arguments' => $this->getDataFormatter()->formatVar($arguments),
], $label, false);
}
Expand Down

0 comments on commit 7a91480

Please sign in to comment.