Skip to content

Commit

Permalink
update wilaya/communes with arabic and add lat/lon
Browse files Browse the repository at this point in the history
  • Loading branch information
kossa committed Apr 19, 2020
1 parent b24760e commit 274a079
Show file tree
Hide file tree
Showing 11 changed files with 14,066 additions and 1,627 deletions.
36 changes: 27 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Algerian Cities

A Laravel package to create/load wilayas and communes of Algeria
A Laravel package to create/load wilayas and communes of Algeria in Arabic and French language, included zip code and latitude/longitude of communes

## Installation

Expand All @@ -11,6 +11,7 @@ php artisan algerian-cities:install

## Using this package
### Basic usage
There is two model `Wilaya` that has many `Commune`, import and use them like any model

```php
namespace App;
Expand All @@ -31,15 +32,25 @@ class AnyClass extends Model
There is multiple helper functions like :

```php
$wilayas = wilayas(); // get all wilayas as $id => $name
$communes = communes(); // get all communes as $id => $name
$communes = communes(16); // get all communes of Algiers(16) as $id => $name
$wilayas = wilayas(); // get all wilayas as $id => $name
$wilayas = wilayas('arabic_name'); // get all wilayas in arabic
$communes = communes(); // get all communes as $id => $name
$communes = communes(16); // get all communes of Algiers(16) as $id => $name
$communes = communes(16, $withWilaya = true); // get all communes of Algiers(16) with name of wilayas like : Alger Centre, Alger
$communes = communes(16, $withWilaya = true, $name = "arabic_name"); // get all communes of Algiers(16) with name of wilayas in arabic like : الجزائر الوسطى, الجزائر

$single_commune = commune(1); // get a single commune model
$single_commune = commune(1, $withWilaya = true); // get a single commune model include wilaya
$single_wilaya = wilaya(1); // get a single wilaya
```


### Blade/Views

You can use any helper/model above and use it in select

```php

// wilayas
<select>
@foreach (wilayas() as $id => $wilaya)
Expand All @@ -54,16 +65,23 @@ $communes = communes(16); // get all communes of Algiers(16) as $id => $name
@endforeach
</select>

// communes of Algiers
// communes of Algiers(16)
<select>
@foreach (communes($wilaya_id = 16) as $id => $commune)
<option value="{{ $id }}">{{ $commune }}</option>
@endforeach
</select>

// communes with wilaya name : Adrar, Adrar ...
<select>
@foreach (communes(16) as $id => $commune)
@foreach (communes($wilaya_id = null, $withWilaya = true) as $id => $commune)
<option value="{{ $id }}">{{ $commune }}</option>
@endforeach
</select>

// communes with wilaya name : Dar El Beida, Alger
// communes with wilaya name in arabic : أدرار, أدرار ...
<select>
@foreach (communes(null, true) as $id => $commune)
@foreach (communes($wilaya_id = null, $withWilaya = true, 'arabic_name') as $id => $commune)
<option value="{{ $id }}">{{ $commune }}</option>
@endforeach
</select>
Expand All @@ -78,4 +96,4 @@ All contributions are welcome, please follow :


## Credits
The list of wilayas/communes are collected from [algeria-cities](https://github.com/othmanus/algeria-cities)
The list of wilayas/communes are collected from [Wilaya-Of-Algeria](https://github.com/bahinapster/Wilaya-Of-Algeria/)
8 changes: 7 additions & 1 deletion database/migrations/create_cities_table.php.stub
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ class CreateCitiesTable extends Migration
Schema::create('wilayas', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('arabic_name');
$table->decimal('longitude', 9, 6);
$table->decimal('latitude', 9, 6);
$table->timestamps();
});

Schema::create('communes', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('arabic_name');
$table->string('post_code');
$table->unsignedInteger('wilaya_id');
$table->string('zip_code')->nullable();
$table->decimal('longitude', 9, 6);
$table->decimal('latitude', 9, 6);
$table->timestamps();

$table->foreign('wilaya_id')->references('id')->on('wilayas')->onDelete('cascade');
Expand Down
Loading

0 comments on commit 274a079

Please sign in to comment.