PHP code example of tareef / laravel
1. Go to this page and download the library: Download tareef/laravel 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/ */
tareef / laravel example snippets
use Tareef\Laravel\Facades\Tareef;
$result = Tareef::verify($request->file('selfie'));
if ($result->matched) {
return "Welcome back, {$result->name}.";
}
use Tareef\Laravel\Facades\Tareef;
$person = Tareef::register(
name: $request->input('name'),
images: [$request->file('photo')], // UploadedFile, file path, or SplFileInfo
phone: $request->input('phone'), // optional
);
return response()->json([
'uuid' => $person->uuid,
'images_indexed' => $person->imageCount,
]);
$result = Tareef::verify($request->file('selfie'));
if ($result->matched) {
return view('door.open', [
'name' => $result->name,
'score' => $result->score, // lower = closer match
]);
}
return view('door.unknown');
$result = Tareef::compare($request->file('selfie'), $request->file('id_photo'));
if ($result->match) {
return 'Same person — '.round($result->similarity * 100).'% similar';
}
// $result->distance (lower = closer), $result->similarity (1.0 = identical)
$person = Tareef::find($uuid);
$person->addImages([
$request->file('photo_1'),
$request->file('photo_2'),
]);
$people = Tareef::list(limit: 50);
// Illuminate\Support\Collection<Person>
foreach ($people as $p) {
echo "{$p->name} — {$p->imageCount} photos\n";
}
Tareef::delete($uuid);
// or, if you already have the object:
$person->delete();
if (! Tareef::health()) {
Log::warning('Tareef is unreachable.');
}
use Tareef\Laravel\Exceptions\{
FaceAlreadyExistsException,
NoFaceDetectedException,
QuotaExceededException,
AuthenticationException,
ServiceUnavailableException,
TareefException,
};
try {
$person = Tareef::register(name: $name, images: [$file]);
} catch (FaceAlreadyExistsException $e) {
// Same face is already enrolled — fetch the existing record.
$existing = Tareef::find($e->existingUuid);
return back()->with('warning', "Already enrolled as {$existing->name}.");
} catch (NoFaceDetectedException $e) {
return back()->withErrors(['photo' => 'No face was detected. Try a clearer photo.']);
} catch (QuotaExceededException) {
return redirect()->route('billing')->with('error', 'Plan quota exhausted.');
} catch (AuthenticationException) {
Log::critical('TAREEF_API_KEY is missing or revoked.');
abort(500);
} catch (ServiceUnavailableException) {
return back()->with('error', 'Tareef is having issues. Try again in a minute.');
} catch (TareefException $e) {
report($e);
return back()->with('error', $e->getMessage());
}
$person->uuid; // string
$person->name; // ?string
$person->phone; // ?string
$person->imageCount; // int
$person->images; // string[] — URLs/paths returned by the API
$person->createdAt; // ?Carbon\Carbon
$person->addImages([$file]); // → Person
$person->delete(); // → bool
$person->toArray(); // → array
$result->matched; // bool — branch on this
$result->uuid; // ?string (the matched person's UUID, if any)
$result->name; // ?string
$result->score; // ?float (lower = closer; <0.35 = confident match)
$result->samples; // ?int (how many reference photos contributed)
$result->status; // 'ok' | 'not_found'
$result->message; // ?string
$result->match; // bool — same person? (uses the app's strictness)
$result->distance; // ?float (cosine distance; lower = closer)
$result->similarity; // ?float (1 − distance; 1.0 = identical)
$result->threshold; // ?float (the cutoff the decision used)
$result->status; // 'ok'
use Illuminate\Support\Facades\Http;
Http::fake([
'*/api/v1/verify' => Http::response([
'success' => true, 'uuid' => 'fixture-uuid',
'name' => 'Test Person', 'score' => 0.1, 'samples' => 1,
]),
]);
$result = Tareef::verify(UploadedFile::fake()->image('selfie.jpg'));
$this->assertTrue($result->matched);
$this->assertSame('Test Person', $result->name);
bash
php artisan vendor:publish --tag=tareef-config