PHP code example of zarbinco / laravel-iran-locations

1. Go to this page and download the library: Download zarbinco/laravel-iran-locations library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zarbinco / laravel-iran-locations example snippets


return [
    'storage' => [
        'driver' => env('IRAN_LOCATIONS_DRIVER', 'database'),

        'json' => [
            'cache' => env('IRAN_LOCATIONS_JSON_CACHE', false),
            'cache_key' => 'iran_locations.json_data',
        ],
    ],

    'admin' => [
        'enabled' => false,
        'prefix' => 'admin/iran-locations',
        'middleware' => ['web', 'auth'],
    ],

    'api' => [
        'enabled' => false,
        'prefix' => 'iran-locations/api',
        'middleware' => ['api'],
    ],
];

use Zarbin\IranLocations\Facades\IranLocations;

$provinces = IranLocations::all('provinces');

$tehran = IranLocations::find('city', 's.01.01.01.01');

$cityOptions = IranLocations::options('cities', [
    'province_code' => 'p.01',
]);

$matches = IranLocations::search('تهران');

use Zarbin\IranLocations\Contracts\LocationReadRepository;

final class LocationController
{
    public function __construct(
        private readonly LocationReadRepository $locations,
    ) {}

    public function cities()
    {
        return $this->locations->options('cities', [
            'province_code' => 'p.01',
        ]);
    }
}

use Zarbin\IranLocations\Models\City;
use Zarbin\IranLocations\Models\CityRegion;
use Zarbin\IranLocations\Models\Neighborhood;
use Zarbin\IranLocations\Models\Province;

$province = Province::query()->byCode('p.01')->first();

$cities = City::query()
    ->forProvince($province)
    ->active()
    ->ordered()
    ->get();

$regions = CityRegion::query()
    ->forCityCode('s.01.01.01.01')
    ->orderedByNumber()
    ->get();

$neighborhoods = Neighborhood::query()
    ->forRegionCode('r.01.01.01.01.05')
    ->ordered()
    ->get();

'api' => [
    'enabled' => true,
],

'admin' => [
    'enabled' => true,
],
bash
php artisan vendor:publish --tag=iran-locations-config
php artisan vendor:publish --tag=iran-locations-migrations
php artisan migrate
php artisan iran-locations:sync --dry-run
php artisan iran-locations:sync
bash
php artisan iran-locations:status
php artisan iran-locations:doctor