Laravel's Eloquent method getKey() returns the first number of the UUID
<p>I have a <code>User</code> and a <code>Role</code> model extending <a href="https://github.com/cartalyst/sentinel" rel="nofollow noreferrer">Catalyst's Sentinel</a> package.</p>

<p>Everything works fine if I use the default incrementing primary key. When I change it to use UUIDs it acts weird. Everything works fine except for a little detail.</p>

<p>Here's the <a href="https://github.com/cartalyst/sentinel/blob/dc0f3ecbbcb2d3f9fbd5f1b9d990524f30ef79e1/src/Users/EloquentUser.php#L202" rel="nofollow noreferrer">code snippet</a> to check whether the <code>User</code> belongs to a <code>Role</code> or not:</p>

<pre><code>public function inRole($role)
{
    if ($role instanceof RoleInterface) {
        $roleId = $role-&gt;getRoleId();
    }
    foreach ($this-&gt;roles as $instance) {
        if ($role instanceof RoleInterface) {
            if ($instance-&gt;getRoleId() === $roleId) {
                return true;
            }
        } else {
            if ($instance-&gt;getRoleId() == $role || $instance-&gt;getRoleSlug() == $role) {
                return true;
            }
        }
    }
    return false;
}
</code></pre>

<p>What that code does is: if I pass an instance of <code>Role</code> it loops through all the user's roles and check whether any of them match the provided <code>$role</code>'s id.</p>

<p>Here's the <code>$user-&gt;roles</code> (<code>$this-&gt;roles</code>) relationship:</p>

<pre><code>public function roles()
{
    return $this-&gt;belongsToMany(static::$rolesModel, 'role_users', 'user_id', 'role_id')-&gt;withTimestamps();
}
</code></pre>

<p>The <code>$role-&gt;getRoleId()</code> correctly returns the UUID: <code>"8fbc99e2-3cbb-4e98-b0e3-4c88027d787f"</code></p>

<p>But the <code>$instance-&gt;getRoleId()</code> returns <code>8</code>, or whatever the first numeric character of the UUID is. If the first character is a letter then it returns <code>0</code>.</p>

<p>I have confirmed that <code>$instance</code> is indeed an instance of <code>RoleInterface</code> so I think it should behave exactly the same as <code>$role</code>.</p>

<p>I have also added <code>public $incrementing = false</code> to both models.</p>

<p>I have made several checkpoints across all the vendor functions that are called and I can't figure out why this is happening.</p>

<p>Any help is greatly appreciated.</p>

<p>I have opened a new issue on their GitHub repository so here's the link to keep the answers in sync: github.com/cartalyst/sentinel/issues/289 (sorry, I can't post more than 2 links)</p>