Advanced

Passkey Model

The Passkey Eloquent model provided by the Laravel Passkey API package.

The Passkey model represents a single registered WebAuthn credential in the database.

Namespace: Xefi\LaravelPasskey\Models\Passkey

Properties

PropertyTypeDescription
$idintPrimary key
$passkeeable_idintID of the polymorphic owner
$passkeeable_typestringClass of the polymorphic owner (e.g. App\Models\User)
$labelstringHuman-readable name for this passkey
$credential_idstringBase64-encoded WebAuthn credential ID
$challengestringBase64url-encoded challenge used during the last registration
$public_keystringBase64-encoded CBOR-encoded COSE public key
$created_atCarbon
$updated_atCarbon

Relationships

passkeeable()

Returns the model that owns this passkey (polymorphic).

public function passkeeable(): MorphTo
$passkey = Passkey::find(1);

$user = $passkey->passkeeable; // App\Models\User instance (or any other model)

Direct usage

You can query the Passkey model directly in your own code:

use Xefi\LaravelPasskey\Models\Passkey;

// Find a passkey by credential ID
$passkey = Passkey::where('credential_id', $credentialId)->firstOrFail();

// Get the owner behind a passkey
$user = $passkey->passkeeable;

// Delete a specific passkey belonging to the authenticated user
Passkey::where('id', $passkeyId)
    ->where('passkeeable_id', auth()->id())
    ->where('passkeeable_type', \App\Models\User::class)
    ->delete();

Fillable fields

The following fields are mass-assignable:

protected $fillable = [
    'label',
    'passkeeable_id',
    'passkeeable_type',
    'credential_id',
    'challenge',
    'public_key',
];