PHP code example of diegocopat / laravel-geodata

1. Go to this page and download the library: Download diegocopat/laravel-geodata 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/ */

    

diegocopat / laravel-geodata example snippets


// config/geodata.php

return [
    'tables' => [
        'countries' => 'countries',
        'regions' => 'regions',
        'provinces' => 'provinces',
        'cities' => 'cities',
    ],
    '

use DiegoCopat\LaravelGeodata\Facades\GeoData;

// Countries
GeoData::countries();                          // active countries
GeoData::countries(es
GeoData::regions();
GeoData::provinces();
GeoData::provincesByRegion('04');              // by region code

// Cities
GeoData::cities();                             // all active cities
GeoData::citiesByProvince('TN');               // by province code
GeoData::searchCities('Trento');               // search by name
GeoData::searchCities('Rover', 'TN');          // search within province

// Lookups
GeoData::findByBelfiore('L378');               // city: Trento
GeoData::findByBelfiore('Z129');               // country: Romania
GeoData::findByCap('38122');                   // cities by postal code

// Utilities
GeoData::isItaly('IT');                        // true

use DiegoCopat\LaravelGeodata\Facades\FiscalCode;

// Generate
$cf = FiscalCode::generate([
    'firstname' => 'Mario',
    'lastname' => 'Rossi',
    'gender' => 'M',
    'birth_date' => '1990-01-15',
    'birth_city' => 'Trento',
    'birth_province' => 'TN',
]);
// Returns: RSSMRA90A15L378X

// Generate with direct Belfiore code
$cf = FiscalCode::generate([
    'firstname' => 'Mario',
    'lastname' => 'Rossi',
    'gender' => 'M',
    'birth_date' => '1990-01-15',
    'belfiore_code' => 'L378',
]);

// Generate for foreign-born
$cf = FiscalCode::generate([
    'firstname' => 'Ion',
    'lastname' => 'Popescu',
    'gender' => 'M',
    'birth_date' => '1988-03-10',
    'birth_country' => 'Romania',
]);

// Validate
FiscalCode::validate('RSSMRA90A15L378X'); // true or false

// Parse
$data = FiscalCode::parse('RSSMRA90A15L378X');
// Returns:
// [
//     'surname_code' => 'RSS',
//     'firstname_code' => 'MRA',
//     'birth_year' => '1990',
//     'birth_month' => 1,
//     'birth_day' => 15,
//     'gender' => 'M',
//     'belfiore_code' => 'L378',
//     'birth_date' => '1990-01-15',
//     'birth_place' => 'Trento',
//     'is_foreign' => false,
//     'omocodia_level' => 0,
// ]

use DiegoCopat\LaravelGeodata\Models\{Country, Region, Province, City};

// Scopes
Country::active()->get();
City::byProvince('TN')->get();
City::byBelfiore('L378')->first();
City::capitals()->get();

// Relationships
$city = City::find(1);
$city->province;
$city->province->region;
$city->province->region->country;

$province = Province::byCode('TN')->first();
$province->cities;
$province->region;
bash
php artisan vendor:publish --tag=geodata-config
bash
php artisan migrate
php artisan geodata:seed