PHPackages                             iamraghavan/rj-geo-locator - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. iamraghavan/rj-geo-locator

ActiveLibrary[API Development](/categories/api)

iamraghavan/rj-geo-locator
==========================

Laravel package to manage country, state, and city data with dynamic form elements and REST API.

012PHP

Since Jan 9Pushed 1y ago1 watchersCompare

[ Source](https://github.com/iamraghavan/rj-geo-locator)[ Packagist](https://packagist.org/packages/iamraghavan/rj-geo-locator)[ RSS](/packages/iamraghavan-rj-geo-locator/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

RJ Geo Locator
==============

[](#rj-geo-locator)

**Package Name**: rj-geo-locator
**Version**: 1.0.0
**Author**: Raghavan
**License**: MIT
**Packagist URL**:

Description
-----------

[](#description)

`rj-geo-locator` is a Laravel package that provides dynamic location-based select inputs for **Country**, **State**, and **City**. This package allows developers to populate the location dropdown fields dynamically in forms using data imported from SQL files. It also includes a RESTful API for fetching country, state, and city data with pagination.

This package is designed to simplify the process of integrating location-based data in Laravel applications, including support for multi-level cascading select inputs and an API interface for location data.

Features
--------

[](#features)

- **Dynamic Location Select Inputs**: Country, State, and City select fields that can be dynamically populated.
- **SQL Import**: Automatically imports country, state, and city data from SQL files into the database.
- **RESTful API**: Provides a paginated API for retrieving countries, states, and cities.
- **Customizable**: Customize class names, IDs, and form attributes for location selects.
- **Laravel Integration**: Easy to integrate and use in Laravel applications.

Installation
------------

[](#installation)

To install the package, follow these steps:

1. **Install via Composer**:

    Run the following command in your Laravel project directory to install the package via Composer:

    ```
    composer require iamraghavan/rj-geo-locator
    ```
2. **Publish Configurations and Views**:

    Once the package is installed, publish the configuration and views using the following Artisan command:

    ```
    php artisan vendor:publish --tag=rjgeo
    ```
3. **Run the Installation Command**:

    To import the SQL data (for countries, states, and cities) into your database, run the package’s install command:

    ```
    php artisan rjgeo:install
    ```

    This will import the data from the `countries.sql`, `states.sql`, and `cities.sql` files into your MySQL database.

Usage
-----

[](#usage)

### Using the Dynamic Select Inputs in Blade Templates

[](#using-the-dynamic-select-inputs-in-blade-templates)

You can use the `country_select()`, `state_select()`, and `city_select()` functions to render dynamic select inputs in your Blade views.

Example:

```
{!! country_select() !!}
```

This will render a select input for countries. Once a country is selected, the available states will be dynamically loaded, and similarly, selecting a state will load the corresponding cities.

### Example Blade Template

[](#example-blade-template)

```

    @csrf

    {{-- Country Select --}}
    {!! country_select() !!}

    {{-- State Select (Change dynamically based on the country) --}}

    {{-- City Select (Change dynamically based on the state) --}}

    Submit

    // Dynamically load states when a country is selected
    document.getElementById('country').addEventListener('change', function () {
        let countryId = this.value;
        axios.get(`/api/states/${countryId}`)
            .then(function (response) {
                // Populate states select dynamically
                document.getElementById('state-container').innerHTML = response.data.html;
            });
    });

    // Dynamically load cities when a state is selected
    document.getElementById('state').addEventListener('change', function () {
        let stateId = this.value;
        axios.get(`/api/cities/${stateId}`)
            .then(function (response) {
                // Populate cities select dynamically
                document.getElementById('city-container').innerHTML = response.data.html;
            });
    });

```

### Using REST API

[](#using-rest-api)

The package also provides a RESTful API for fetching country, state, and city data.

#### Get Countries

[](#get-countries)

To get a list of countries, make a GET request:

```
GET /api/countries

```

#### Get States by Country ID

[](#get-states-by-country-id)

To get states for a given country, make a GET request:

```
GET /api/states/{countryId}

```

#### Get Cities by State ID

[](#get-cities-by-state-id)

To get cities for a given state, make a GET request:

```
GET /api/cities/{stateId}

```

All API responses are paginated.

Configuration
-------------

[](#configuration)

The package comes with a default configuration file located at `config/rjgeo.php`. You can publish the configuration file using the following Artisan command:

```
php artisan vendor:publish --tag=rjgeo
```

### Configuration Options

[](#configuration-options)

- **`class_name`**: Customize the class name for the select input fields.
- **`id_name`**: Customize the id attribute for the select input fields.
- **`use_ajax`**: Enable or disable AJAX loading for location data.
- **`api_enabled`**: Enable or disable the REST API for location data.

Example Configuration
---------------------

[](#example-configuration)

```
return [
    'class_name' => 'location-select',
    'id_name' => 'location',
    'use_ajax' => true,
    'api_enabled' => true,
];
```

Contribution
------------

[](#contribution)

Contributions to this package are welcome! If you want to contribute, please follow the steps below:

1. Fork the repository.
2. Create a new branch.
3. Make your changes and commit them.
4. Submit a pull request with a description of the changes and why they are needed.

License
-------

[](#license)

This package is open-source and available under the [MIT License](https://opensource.org/licenses/MIT).

Credits
-------

[](#credits)

- **Author**: Raghavan
- **Package**: [iamraghavan/rj-geo-locator](https://packagist.org/packages/iamraghavan/rj-geo-locator)

---

###  Health Score

15

—

LowBetter than 3% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/ef731b1c14f1d1dbae86771c17e008672a5c9c3724d4a5674352f82acac94596?d=identicon)[iamraghavan](/maintainers/iamraghavan)

---

Top Contributors

[![iamraghavan](https://avatars.githubusercontent.com/u/87792550?v=4)](https://github.com/iamraghavan "iamraghavan (19 commits)")

### Embed Badge

![Health badge](/badges/iamraghavan-rj-geo-locator/health.svg)

```
[![Health](https://phpackages.com/badges/iamraghavan-rj-geo-locator/health.svg)](https://phpackages.com/packages/iamraghavan-rj-geo-locator)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
