Download the PHP package kazistm/algeria-geo without Composer
On this page you can find all versions of the php package kazistm/algeria-geo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download kazistm/algeria-geo
More information about kazistm/algeria-geo
Files in kazistm/algeria-geo
Package algeria-geo
Short Description Laravel package providing complete Algerian geo data (69 Wilayas and Communes) with slugs, coordinates and optimized seeders.
License MIT
Homepage https://github.com/KaziSTM/algeria-geo
Informations about the package algeria-geo
Algeria Geo Data for Laravel by KaziSTM
🇩🇿 Algeria Administrative Update
This package fully supports Algeria’s latest administrative division:
- ✅ 69 Wilayas (updated law)
- ✅ Complete Communes dataset
- ✅ Normalized naming (FR / AR)
- ✅ Unique slugs for reliable lookups
- ✅ Geographic coordinates (lat/lng)
Unlike many existing packages, this dataset reflects the latest official Algerian administrative structure.
Table of Contents
- Features
- Installation
- 1. Require Package
- 2. Run Install Command
- 3. Optional Publishing
- Usage
- Models
- City (Wilaya)
- Commune
- Basic Retrieval
- Relationships
- City to Communes
- Commune to City
- Static Finders
- City::findByCode()
- Commune::findByPostCode()
- Query Scopes
- searchByName()
- code() (City)
- postCode() (Commune)
- withinRadius() (Commune)
- Helper Methods
- getCoordinates()
- getDisplayName()
- Models
- Data Source
- Contributing
- License
Features
- Eloquent Models:
City(Wilaya) andCommunemodels ready to use. - Relationships: Pre-defined
hasMany(City->Communes) andbelongsTo(Commune->City) relationships. - Database Migrations: Sets up optimized
citiesandcommunestables with proper indexes and constraints. - Database Seeders: Fully updated dataset covering all 69 Algerian Wilayas and their Communes.
- Slug Support: Unique slugs for both Cities and Communes for clean URLs and lookups.
- Data Integrity: Prevents duplicates via composite unique constraints (
wilaya_id + slug). - Robust Seeding: Handles missing/partial data safely and avoids crashes.
- Easy Installation: Single Artisan command (
algeria-geo:install) for migration and optional seeding. - Helpful Query Scopes: Includes scopes for searching by name, code, slug, postal code, and geospatial radius.
- Convenience Methods: Helpers for retrieving coordinates and display names.
- High Test Coverage: Fully tested with >95% Pest coverage ensuring reliability.
- Laravel Compatibility: Supports Laravel 10 → 13 and PHP 8.1 → 8.5.
- Production Ready: Designed for SaaS and real-world geo use cases.
Installation
1. Require Package
Install the package via Composer:
2. Run Install Command
This command checks if the tables exist, runs the migrations if needed, and optionally seeds the database.
Bash
The command will inform you if the tables already exist and skip the process unless --force is used.
3. Optional Publishing
You typically don't need to publish assets, as the package runs migrations directly from its vendor directory.
However, if you need deep customization:
Bash
Usage
Models
Access the models using their namespaces:
City (Wilaya)
Represents an Algerian Wilaya.
| Column | Type | Description |
|---|---|---|
id |
Primary Key | Unique identifier |
code |
int |
Wilaya code (e.g., 16) |
name |
string |
Wilaya name (e.g., "Alger") |
arabic_name |
string |
Wilaya name in Arabic (e.g., "الجزائر") |
slug |
string |
Unique slug (e.g., "algiers") |
longitude |
float | null |
Optional longitude |
latitude |
float | null |
Optional latitude |
created_at |
timestamp |
Timestamp |
updated_at |
timestamp |
Timestamp |
Commune (Daira)
Represents an Algerian Commune (Daira).
| Column | Type | Description |
|---|---|---|
id |
Primary Key | Unique identifier |
post_code |
string | null |
Postal code (nullable) |
name |
string |
Commune name |
wilaya_id |
int |
Foreign key to cities.id |
arabic_name |
string |
Commune name in Arabic |
slug |
string |
Unique per Wilaya (used for lookup & URLs) |
longitude |
float | null |
Optional longitude |
latitude |
float | null |
Optional latitude |
distance |
float | null |
Available after using withinRadius scope |
created_at |
timestamp |
Timestamp |
updated_at |
timestamp |
Timestamp |
⚠️ Note: A unique constraint is enforced on (
wilaya_id,slug) to prevent duplicates.
Basic Retrieval
Relationships
City to Communes
Commune to City
Static Finders
Convenient methods to find a single record by a specific attribute.
City::findByCode()
Finds a City (Wilaya) by its official code.
Commune::findByPostCode()
Finds the first Commune matching the given postal code.
Note: Postal codes might not be strictly unique across all communes in some datasets.
searchByName()
Available on both City and Commune. Searches the name and arabic_name columns.
code() (City)
Filters Cities by their official code.
postCode() (Commune)
Filters Communes by their postal code.
withinRadius() (Commune)
Finds Communes within a specified radius of a given latitude/longitude point using the Haversine formula.
Parameters:
$latitude(float): Latitude of the center point.$longitude(float): Longitude of the center point.$radius(int, optional): The radius distance. Defaults to 10.$unit(string, optional): The unit for the radius ('km' or 'miles'). Defaults to 'km'.
Returns:
- An Eloquent Builder instance. When results are retrieved (
get(),first(), etc.), each Commune model will have an additionaldistanceattribute containing the calculated distance from the center point in the specified unit.
Example (Kilometers):
withinRadius() (Commune)
Finds Communes within a specified radius of a given latitude/longitude point using the Haversine formula.
Parameters:
$latitude(float): Latitude of the center point.$longitude(float): Longitude of the center point.$radius(int, optional): The radius distance. Defaults to 10.$unit(string, optional): The unit for the radius ('km' or 'miles'). Defaults to 'km'.
Returns:
- An Eloquent Builder instance. When results are retrieved (
get(),first(), etc.), each Commune model will have an additionaldistanceattribute containing the calculated distance from the center point in the specified unit.
Example (Kilometers):
Note: This query relies on the latitude and longitude columns being populated in your communes table. Accuracy
depends
on the quality of the coordinate data. Communes with NULL coordinates are automatically excluded from the radius
search.
City::findBySlug()
Finds a City (Wilaya) by its slug.
`
Commune::findBySlu()
Finds a Commune by its slug.
`
Helper Methods
Instance methods available on retrieved models.
getCoordinates()
Available on both City and Commune. Returns coordinates as an associative array or null.
PHP Example:
getDisplayName()
Available on both City and Commune. Returns the name, optionally preferring the Arabic name.
PHP Example:
Data Source
The dataset has been fully updated to reflect Algeria’s latest administrative divisions (69 Wilayas).
Improvements:
- ✅ Complete coverage of all 69 Wilayas
- ✅ Updated and expanded Communes dataset
- ✅ Added geographic coordinates (lat/lng) where available
- ✅ Normalized naming (FR / AR)
- ✅ Added slugs for consistent identification
- ✅ Removed duplicates and fixed inconsistent records
The seeders are designed to be:
- Idempotent (safe to run multiple times)
- Resilient to partial or evolving datasets
- Optimized for performance using chunked upserts
Testing
This package includes a comprehensive test suite built with Pest.
Coverage
- ✅ Models (City, Commune)
- ✅ Seeders (data integrity & edge cases)
- ✅ Install Command (all execution paths)
Test coverage is maintained at >95% to ensure stability and reliability.
Run tests
Run coverage
Contributing
Contributions (bug reports, feature requests, pull requests) are welcome. Please refer to the GitHub repository issues and pull request sections.
License
This package is open-source software licensed under the MIT license.
All versions of algeria-geo with dependencies
illuminate/console Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/database Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/support Version ^10.0 || ^11.0 || ^12.0 || ^13.0
illuminate/filesystem Version ^10.0 || ^11.0 || ^12.0 || ^13.0
spatie/laravel-package-tools Version ^1.16