kossa/algerian-cities

A Laravel package to create/load wilayas and communes of Algeria

v3.0.2 2022-02-07 18:35 UTC

README

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

composer require kossa/algerian-cities
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

namespace App;

use Illuminate\Database\Eloquent\Model;
use Kossa\AlgerianCities\Commune;
use Kossa\AlgerianCities\Wilaya;

class AnyClass extends Model
{
    $wilayas          = Wilaya::all();                           // Get all wilayas
    $communes         = Commune::all();                          // Get all communes
    $algiers_communes = Commune::where('wilaya_id', 16)->get();  // get all communes of Algiers(16)
}

Via helpers

There is multiple helper functions like :

$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

// wilayas
<select>
    @foreach (wilayas() as $id => $wilaya)
        <option value="{{ $id }}">{{ $wilaya }}</option>
    @endforeach
</select>

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

// 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($wilaya_id = null, $withWilaya = true) as $id => $commune)
        <option value="{{ $id }}">{{ $commune }}</option>
    @endforeach
</select>

// communes with wilaya name in arabic : أدرار, أدرار ...
<select>
    @foreach (communes($wilaya_id = null, $withWilaya = true, 'arabic_name') as $id => $commune)
        <option value="{{ $id }}">{{ $commune }}</option>
    @endforeach
</select>

Use package as API

This package include api.php route to use the api, here is the url for :

verbs URI Description
Get /api/wilayas Get all wilayas
Get /api/wilayas/:id Get a specific wilaya by id
Get /api/wilayas/:id/communes Get all communes from a specific wilaya by id
Get /api/communes Get all communes
Get /api/communes/:id Get a specific commune by id
Get /api/search/wilaya/:q Search wilayas by name, arabic name
Get /api/search/commune/:q Search communes by name, arabic name

Contribution

All contributions are welcome, please follow :

  1. PSR-2 Coding Standard
  2. Document any change in behaviour - Make sure the README.md and any other relevant documentation are kept up-to-date.
  3. One pull request per feature - If you want to do more than one thing, send multiple pull requests.

Credits

The list of wilayas/communes are collected from Wilaya-Of-Algeria