PHP code example of schaefersoft / laravel-swiss-eid
1. Go to this page and download the library: Download schaefersoft/laravel-swiss-eid library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
schaefersoft / laravel-swiss-eid example snippets
use SchaeferSoft\SwissEid\Facades\SwissEid;
$pending = SwissEid::verify()
->ageOver18()
->forUser(auth()->id())
->create();
// $pending->qrCode() → SVG string, embed with {!! !!}
// $pending->deeplink → universal link to open the wallet app directly
// $pending->statusUrl() → JSON polling endpoint for your frontend
// $pending->id → UUID to look up the result later
use App\Models\User;
use SchaeferSoft\SwissEid\Events\VerificationCompleted;
Event::listen(VerificationCompleted::class, function ($event) {
$result = $event->verification->toResult();
if ($result->isSuccessful() && $result->isAdult()) {
User::find($event->verification->user_id)?->update(['verified_at' => now()]);
}
});
$result = SwissEid::getVerification($pending->id); // or the verifier ID
if ($result->isSuccessful()) {
$firstName = $result->get('given_name');
$isAdult = $result->isAdult(); // age_over_18 convenience
$raw = $result->credentialData; // decrypted array, or null
}
$result = SwissEid::refresh($pending->id); // or the verifier ID
use SchaeferSoft\SwissEid\Events\VerificationCompleted;
use SchaeferSoft\SwissEid\Events\VerificationFailed;
use SchaeferSoft\SwissEid\Events\VerificationExpired;
Event::listen(VerificationCompleted::class, function ($event) {
$user = User::find($event->verification->user_id);
$user->update(['verified_at' => now()]);
});