PHP code example of plin-code / laravel-istat-geography
1. Go to this page and download the library: Download plin-code/laravel-istat-geography 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/ */
plin-code / laravel-istat-geography example snippets
// app/Models/Region.php
namespace App\Models;
use PlinCode\IstatGeography\Models\Geography\Region as BaseRegion;
class Region extends BaseRegion
{
// Add your project-specific logic here
public function customMethod()
{
return $this->provinces()->count();
}
}
// app/Models/Province.php
namespace App\Models;
use PlinCode\IstatGeography\Models\Geography\Province as BaseProvince;
class Province extends BaseProvince
{
// Add your project-specific logic here
}
// app/Models/Municipality.php
namespace App\Models;
use PlinCode\IstatGeography\Models\Geography\Municipality as BaseMunicipality;
class Municipality extends BaseMunicipality
{
// Add your project-specific logic here
}
// In app/Console/Kernel.php or in your existing command
Artisan::command('geography:import', function () {
$this->info('Starting geographical data import...');
try {
$count = \PlinCode\IstatGeography\Facades\IstatGeography::import();
$this->info("Import completed successfully! Imported {$count} municipalities.");
} catch (\Exception $e) {
$this->error('Error during import: ' . $e->getMessage());
}
})->purpose('Import regions, provinces and municipalities from ISTAT');