trinityrank/geo-location

GeoLocation - show or hide operaters in selected countries

v1.1 2024-04-22 12:56 UTC

This package is auto-updated.

Last update: 2024-10-22 14:11:54 UTC


README

Latest Version on Packagist Total Downloads

Choose to show or hide Operaters by choosing the countries from list.

Installation

Step 1: Install package

To get started with Laravel Geo Location, use Composer command to add the package to your composer.json project's dependencies:

    composer require trinityrank/geo-location

Step 2: Migration

  • You need to publish migration from package
    php artisan vendor:publish --provider="Trinityrank\GeoLocation\GeoLocationServiceProvider" --tag="geolocation-migration"
  • And then you need to run migration for alltenant(s)
    php artisan tenant:artisan "migrate"
  • Or only for one speciffic tenant
    php artisan tenant:artisan "migrate" --tenant=[--TENANT-ID--]

Step 3: Operaters Model database

Add this fields to '$fillable' inside Operaters model

    public $fillable = [
        ...
        'geolocation_option',
        'geolocation_countries',
    ];

Step 4: Add field

  • Add field to your (Operater) resource into "fields" method
    use Trinityrank\GeoLocation\GeoLocationPanel;
    
    ...
    
    GeoLocationPanel::make()
  • Or if you use conditional fields than just add this into "fields" method
    $this->getGeoLocationPanel('GeoLocation Page Settings', 'geolocation')

Step 5: If you are using conditional fields

Add this in tenant config

    'conditional_fields' => [
        ...

        'operater' => [
            'geolocation' => [
                'visible' => true
            ]
        ]

        ...
    ]

Step 6: Frontend part

  • Without token
    use Trinityrank\GeoLocation\GeoLocationOperater;

    ...

    $operaters = GeoLocationOperater::list($operaters_array);
  • With token

Add new variable in .ENV file

    GEOLOCATION_API_TOKEN=[--Replace-this-with-website-token--]

You can connect with 'config/main.php' file

    'geolocation_api_token' => env('GEOLOCATION_API_TOKEN', null),

Then we can use our Geo Location

    use Trinityrank\GeoLocation\GeoLocationOperater;

    ...

    $operaters = GeoLocationOperater::list($operaters_array, $api_token = [optional]);