Laravel-Algereography
Laravel-Algereography allows you to add Migrations, Seeders and Models of Algerian Wilayas and Dairas to your existing or new cool Laravel project .
- 58 Wilayas.
- 548 Dairas.
- Support both Arabic and French languages.
- Built in models relationships, so you can for example do: Daira::find(1)->wilaya
to get the Wilaya of Daira with the id=1.
Installation
Step 1 - Require the package
composer require thehocinesaad/laravel-algereography
Step 2: Install the package
php artisan algereography:install
This command will do those good stuff for you:
-
Publish two Models,
Wilaya
andDaira
toapp/Models
. -
Publish two Migrations,
create_wilayas_table
andcreate_dairas_table
todatabase/migrations
-
Publish two Seeders,
WilayaSeeder
andDairaSeeder
todatabase/seeders
-
Run the two Migrations (
create_wilayas_table
andcreate_dairas_table
)
Note: this operation will automatically overwrite any table with the name ofwilayas
anddairas
-
Run the two Seeders (
WilayaSeeder
andDairaSeeder
) -
Finally, it prints Done! to make you know that everything is succefully finished then it will print 1 2 3 Viva l'Algérie! just to make you a little bit proud of your country
❤️
Step 3:
There is no step 3, you're done
Check out your database and you will find two new tables, wilayas
and dairas
.
How can I use the package
As mentioned before, the package publishes two models Wilaya
and Daira
, use them just like any other model in your project.
Get all Wilayas
Wilaya::all();
Get all Dairas
Daira::all();
Get Dairas of a Wilaya
Wilaya::findOrFail(15)->dairas
Get Wilaya of a Daira
Daira::findOrFail(205)->wilaya;
Note: Don't forget to import the models first:
use App\Models\Wilaya;
use App\Models\Daira;
Helpers
You can also use the package using some Helpers I added that will make your life easier.
Helpers list:
$wilayas = wilayas(); // Get all Wilayas in all languages
$ar_wilayas = wilayas('ar'); // Get all Wilayas in arabic
$ar_wilayas = wilayas('fr'); // Get all Wilayas in french
//
$wilaya = wilaya(15); // Get individuel Wilaya in all languages
$ar_wilaya = wilaya(15, 'ar'); // Get individuel Wilaya in arabic
$wilaya = wilaya(15, 'fr'); // Get individuel Wilaya in french
//
$dairas = dairas(); // Get all Dairas in all languages
$ar_dairas = dairas('ar'); // Get all Dairas in arabic
$fr_dairas = dairas('fr'); // Get all Dairas in french
//
$dairas = dairasOf(15); // Get all Dairas of a Wilaya in all languages
$dairas = dairasOf(15, 'ar'); // Get all Dairas of a Wilaya in arabic
$dairas = dairasOf(15, 'fr'); // Get all Dairas of a Wilaya in french
->name
and it will automatically get the name in the correct language, so there is no need to do ->ar_name
to get the name in arabic.
When specifying the language, to access the name attribute just do Example
$fr_wilaya = wilaya(15, 'fr'); // $fr_wilaya->name will be 'Tizi Ouzou'
$ar_wilaya = wilaya(15, 'ar'); // $ar_wilaya->name will be 'تيزي وزو'
How cool is that!
Contributing
Thank you for considering contributing to Laravel-Algereography project! Feel free to contribute in any way, we welcome every contribution.
License
Laravel-Algereography project is open-sourced software licensed under the MIT license.