mahdiabbariki/iranprovinces

This package includes models and tables for provinces and their respective cities, which will be integrated into your project.

1.2.0 2023-09-25 13:35 UTC

This package is auto-updated.

Last update: 2024-09-25 16:04:38 UTC


README

This package offers functionality to manage Iran's provinces and cities through database tables. It comes with flexible configuration options, allowing you to:

  • Choose whether or not to create a table for cities.
  • Decide whether to include latitude and longitude data in the cities table.
  • Add or exclude timestamps in the tables.

Persian Install Guide

راهنمای نصب فارسی

Installation

To get started, run the following command:

    composer require MahdiAbbariki/IranProvinces

For Laravel Versions Prior to v6

For Laravel versions older than v6, you need to add the following line to the providers array in the config/app.php file:

    'providers' => [
    // ...
    MahdiAbbariki\IranProvinces\IranProvincesServiceProvider::class, // Add this line at the end of the provider array
    ],

the package is successfully integrated into your project.

After that, run the following command to publish the package's configuration, migration, and seeder files:

    php artisan vendor:publish --provider="MahdiAbbariki\IranProvinces\IranProvincesServiceProvider"

Make sure to edit the configuration file ( config/iranProvinces.php ) to match your specific requirements. The default configurations are suitable for most users.

Once you've customized the configuration, run your migrations.

    php artisan migrate

Seeding

You have two options for seeding the data.

You can execute this command to run the designated seeders included with this package:

    php artisan province:seed

Alternatively, you can add the following lines to the run method in the DatabaseSeeder class located in the database/seeders directory:

    $this->call([
        //...
        \MahdiAbbariki\IranProvinces\Database\Seeders\IranProvincesTableSeeder::class,
        \MahdiAbbariki\IranProvinces\Database\Seeders\IranProvincesCitiesTableSeeder::class,
        //...
    ]);

then you can use the built-in laravel seed command:

    php artisan db:seed

Now, your models and tables are ready for use.

Examples

Here are some examples of how to use them:

    use MahdiAbbariki\IranProvinces\Models\Province;
    use MahdiAbbariki\IranProvinces\Models\City;

    $province = Province::find(1);
    $cities = $province->cities;

    $city = City::find(1);
    $province = $city->province;

Contribution

If you encounter any bugs, please report them to info@mahdiab.ir. Your contributions are welcome!