elaborate-code / laravel-algerian-provinces
Add a table of algerian provinces to your project
Requires
- php: ^8.1
- ext-pdo_sqlite: *
- calebporzio/sushi: ^2.4
- illuminate/contracts: ^9.0
- spatie/laravel-package-tools: ^1.9.2
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-12-08 23:32:45 UTC
README
Algerian provinces Eloquent model for Laravel applications.
Installation
Install the package via composer:
composer require elaborate-code/laravel-algerian-provinces
Requirements:
- 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.