PHP code example of ecolabor / laravel-swiss-uid-search
1. Go to this page and download the library: Download ecolabor/laravel-swiss-uid-search 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/ */
ecolabor / laravel-swiss-uid-search example snippets
use Ecolabor\SwissUid\Facades\SwissUid;
// Mit formatierter UID
$company = SwissUid::getByUid('CHE-123.456.789');
// Oder nur mit Ziffern
$company = SwissUid::getByUid('123456789');
if ($company) {
echo $company->organisationName; // Firmenname
echo $company->uidFormatted; // CHE-123.456.789
echo $company->address->getOneLiner(); // Strasse 1, 8000 Zürich
echo $company->legalFormText; // Aktiengesellschaft
echo $company->vatNumberFormatted; // CHE-123.456.789 MWST
echo $company->isActive(); // true/false
echo $company->isVatRegistered(); // true/false
echo $company->isInCommercialRegister(); // true/false
}
use Ecolabor\SwissUid\Facades\SwissUid;
// Nach Name suchen
$result = SwissUid::searchByName('Migros');
// Nach Ort suchen
$result = SwissUid::searchByLocation('Zürich');
// Kombinierte Suche mit allen Parametern
$result = SwissUid::search([
'organisationName' => 'AG',
'town' => 'Bern',
'canton' => 'BE',
'zipCode' => '3000',
'legalFormId' => 6, // Aktiengesellschaft
'uidregStatusEnterpriseActive' => true, // Nur aktive
'maxNumberOfRecords' => 50,
'searchMode' => 'auto', // auto, exact, wild
]);
foreach ($result->entities as $company) {
echo "{$company->organisationName} - {$company->uidFormatted}\n";
}
// Ergebnisse filtern
$activeOnly = $result->onlyActive();
$vatRegistered = $result->onlyVatRegistered();
$inHr = $result->onlyInCommercialRegister();
// Für Dropdowns
$options = $result->toSelectOptions();
// ['123456789' => 'Firma AG (CHE-123.456.789)', ...]
use Ecolabor\SwissUid\Facades\SwissUid;
// Prüfen ob UID gültig ist
if (SwissUid::validateUid('CHE-123.456.789')) {
echo "UID ist gültig!";
}
// MWST-Nummer validieren
if (SwissUid::validateVatNumber('CHE-123.456.789')) {
echo "MWST-Nummer ist gültig!";
}
use Ecolabor\SwissUid\Rules\ValidSwissUid;
// Nur Format validieren (schnell, kein API-Call)
$request->validate([
'uid' => ['
]);