Algerian provinces Eloquent model for Laravel applications.
Install the package via composer:
composer require elaborate-code/laravel-algerian-provinces
Requirements:
- SQLite.
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.
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');
}
}
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.
vendor/bin/pint
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.