PHP code example of simplecms / region

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

    

simplecms / region example snippets


use \SimpleCMS\Region\Traits\RegionTrait;

$query->withGeoDistance(23.9999,133.9999,10000);

use SimpleCMS\Region\Facades\Region; 

Region::getAll(); // Returns the complete list
Region::findRegion(string $code = 'Administrative Identifier'); // Query geographic information
Region::getAllChildren(string $code = 'Administrative Identifier'); // Query all children
Region::getChildren(string $code, int $deep = 0); // Query down with depth
Region::checkName(string $name); // Check name validity
Region::checkCode(string $code); // Check validity of administrative code
Region::checkArea(string $area); // Check area code validity
Region::checkNumber(string $number); // Check phone number validity
Region::checkZip(string $zip); // Check zip code validity supports full zip code

use SimpleCMS\Region\Casts\Point; 
use SimpleCMS\Region\Casts\LineString; 
use SimpleCMS\Region\Casts\Polygon; 

public $casts = [
    'geo' => Point::class,
    'geo' => LineString::class,
    'geo' => Polygon::class
];

distance($lat1,$lng1,$lat2,$lng2); // Calculate distance between two locations

$rules = [
    'region' => 'region_code', // Check administrative code
    'region_name' => 'region_name', // Check geographic name
    'region_zip' => 'region_zip', // Check zip code
    'region_area' => 'region_area', // Check area code
    'region_number' => 'region_number', // Check phone number (landline with area code)
];
$messages = [
    'region.region_code' => 'Incorrect administrative code',
    'region_name.region_name' => 'Incorrect geographic name',
    'region_zip.region_zip' => 'Incorrect zip code',
    'region_area.region_area' => 'Incorrect area code',
    'region_number.region_number' => 'Incorrect area code',
];
$data = $request->validate($rules,$messages);

use SimpleService;
// Get distance
$service->selectDistance(float $lat = 23.23211, float $lng = 111.23123,string $column = 'location');
// Query by record
$service->queryDistance(float $lat = 23.23211, float $lng = 111.23123, float $maxDistance = 50,string $column = 'location')