1. Go to this page and download the library: Download zakiyou/benin-geo 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/ */
zakiyou / benin-geo example snippets
use Zakiyou\BeninGeo\BeninGeo;
$geo = new BeninGeo();
// Récupérer tous les départements
$departments = $geo->departments();
// Récupérer les communes d'un département spécifique
$communes = $geo->communes('Atlantique');
// Compter les départements
$totalDepartments = $geo->countDepartments();
// Compter les communes d'un département
$countCommunes = $geo->countCommunes('Atlantique');
// Obtenir le nombre total de communes au Bénin
$totalCommunes = $geo->countTotalCommunes();
// Obtenir toutes les communes groupées par département
$groupedCommunes = $geo->allCommunesGrouped();
namespace App\Http\Controllers;
use Illuminate\Http\Controller;
use Zakiyou\BeninGeo\BeninGeo;
class LocationController extends Controller
{
public function index(BeninGeo $geo)
{
$departments = $geo->departments();
return view('locations.index', compact('departments'));
}
public function communes($department, BeninGeo $geo)
{
$communes = $geo->communes($department);
return response()->json($communes);
}
}
use Zakiyou\BeninGeo\BeninGeo;
use Zakiyou\BeninGeo\DepartmentNotFoundException;
$geo = new BeninGeo();
try {
$communes = $geo->communes('DépartementInexistant');
} catch (DepartmentNotFoundException $e) {
// Gestion de l'erreur
echo "Erreur : " . $e->getMessage();
// Log de l'erreur
\Log::error('Département non trouvé: ' . $e->getMessage());
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.