PHP code example of kreatif / laravel-codice-fiscale
1. Go to this page and download the library: Download kreatif/laravel-codice-fiscale 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/ */
kreatif / laravel-codice-fiscale example snippets
use Kreatif\CodiceFiscale\Actions\CalculateCodiceFiscale;
$codiceFiscale = CalculateCodiceFiscale::calculate([
'firstname' => 'Mario',
'lastname' => 'Rossi',
'dob' => '1990-01-01',
'gender' => 'M',
'pob' => 'Roma', // or codice_catastale like 'z222'.
]);
// Result: RSSMRA90A01H501Z
use Kreatif\CodiceFiscale\Actions\ValidateCodiceFiscale;
// Basic validation (format and checksum)
$isValid = ValidateCodiceFiscale::isValid('RSSMRA90A01H501Z');
// Strict validation (compares against personal data)
$isValid = ValidateCodiceFiscale::isValidStrict('RSSMRA90A01H501Z', [
'firstname' => 'Mario',
'lastname' => 'Rossi',
'dob' => '1990-01-01',
'gender' => 'M',
'pob' => 'Roma',
]);
use Kreatif\CodiceFiscale\Rules\ValidCodiceFiscale;
$validator = Validator::make($data, [
'codice_fiscale' => ['ice_fiscale',
]);
use Kreatif\CodiceFiscale\Rules\CodiceFiscaleMatchesData;
$validator = Validator::make($data, [
'first_name' => 't_name',
'lastname' => 'last_name',
'dob' => 'dob',
'gender' => 'gender',
'pob' => 'pob',
])
],
]);
// Or with default field names:
$validator = Validator::make($data, [
'codice_fiscale' => '
use Kreatif\CodiceFiscale\Models\GeoLocation;
// Get all Italian municipalities
$comuni = GeoLocation::comuni()->valid()->get();
// Get municipalities
$altoAdige = GeoLocation::comuni()->get();
// Get all foreign states
$foreignStates = GeoLocation::foreignStates()->get();
use Kreatif\CodiceFiscale\Filament\Forms\Traits\HasUserBasicFilamentFields;
class UserForm
{
use HasUserBasicFilamentFields;
public static function configure(Schema $schema): Schema
{
return $schema->components([
...self::getAllCodiceFiscaleFields(),
// Your other fields...
]);
}
}
use Kreatif\CodiceFiscale\Filament\Forms\Components\CodiceFiscale;
// Simple field
CodiceFiscale::make('codice_fiscale');
// With generator and validator
CodiceFiscale::make('codice_fiscale')
->generator()
->validator();