PHP code example of dynamiccarrots / laravel-ip2location

1. Go to this page and download the library: Download dynamiccarrots/laravel-ip2location 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/ */

    

dynamiccarrots / laravel-ip2location example snippets


   /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('ip2location', function (Blueprint $table) {
          $table->integer('ip_from')->unsigned();
          $table->integer('ip_to')->unsigned();
          $table->char('country_code', 2);
          $table->string('country_name', 64)->nullable();
          $table->string('region_name', 128)->nullable();
          $table->string('city_name', 128)->nullable();
          $table->double('latitude')->nullable();
          $table->double('longitude')->nullable();
          $table->string('zip_code', 30)->nullable();
          $table->string('time_zone', 8)->nullable();
          // Setting index
          $table->index('ip_from', 'idx_ip_from');
          $table->index('ip_to', 'idx_ip_to');
          $table->index(['ip_from', 'ip_to'], 'idx_ip_from_to');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('ip2location');
    }

    protected $commands = [
        RefreshIp2Location::class
    ];

echo Ip2Location::lookUpIpLocation('8.8.8.8')->country_code

echo Ip2Location::getClientsLocation()->country_code

# php artisan migrate

# php artisan make:command RefreshIp2Location

# php artisan ip2location:refresh