Skip to content

al-jazair/laravel-algerian-provinces

Repository files navigation

Laravel Algerian provinces

Packagist Version Packagist Downloads GitHub Workflow Status GitHub Workflow Status

banner

Algerian provinces Eloquent model for Laravel applications.

Installation

Install the package via composer:

composer require elaborate-code/laravel-algerian-provinces

Requirements:

  1. SQLite.

Publishing config file [Optional]

You can publish the config file with:

php artisan vendor:publish --tag="algerian-provinces-config"

This is the contents of the published config file:

return [
    'columns_names' => [
        'fr_name' => null, // defaults to fr_name
        'ar_name' => null, // defaults to ar_name
    ],
];

That allows you to rename columns names.

Usage

Now you have access to the ElaborateCode\AlgerianProvinces\Models\Wilaya

use ElaborateCode\AlgerianProvinces\Models\Wilaya;

$wilayas = Wilaya::all();

$wilayas = Wilaya::find(31); // Model of: ["id" => 31, "fr_name" => "Oran", "ar_name" => "وهران"]

$wilayas = Wilaya::arr(); // Wilaya::all()->toArray()

$fr_names = Wilaya::frNames(); // Wilaya::pluck('fr_name')

$ar_names = Wilaya::arNames(); // Wilaya::pluck('ar_name')
namespace App\Models;

use ElaborateCode\AlgerianProvinces\Models\Wilaya;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class User extends Model
{
    // use as relationship
    
    public function birthWilaya(): BelongsTo
    {
        return $this->belongsTo(Wilaya::class, 'birth_wilaya', 'fr_name');
    }
}

Sushi

This package requires 0 config, and comes with no migrations or seeders thanks to the wonderful package calebporzio/sushi. That allows us to offer a ready to use model without going the extra steps of affecting your database.

However this dependency requires SQLite to be setup on your system!

If you prefer having a table in your database checkout v1 which doesn't depand on calebporzio/sushi.

Testing

vendor/bin/pint

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.