PHP code example of aestheticraza / laravelglobe

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

    

aestheticraza / laravelglobe example snippets


namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Aestheticraza\LaravelGlobe\Traits\HasLocation;

class Order extends Model 
{
    use HasLocation;
}

$order = Order::find(1);

// Standard Relational Lookups
echo $order->country->name; // e.g. "Pakistan"
echo $order->state->name;   // e.g. "Punjab"
echo $order->city->name;    // e.g. "Lahore"

// Dynamic Virtual Accessors (Provided by the Trait)
echo $order->full_address;           // "Lahore, Punjab, Pakistan"
echo $order->country->emoji;         // "🇵🇰"
echo $order->country->phone_code;    // "+92"

// Fetch all "active" delivery riders within 25 KM of a customer's drop-off coordinates
$ridersNearMe = Rider::where('status', 'active')
                    ->withinRadius($customerLat, $customerLng, 25)
                    ->get();

// Find the closest branch of a restaurant chain natively!
$closestBranch = RestaurantBranch::withinRadius(31.5204, 74.3587, 10)->first();

use Aestheticraza\LaravelGlobe\Models\Country;

$country = Country::where('iso2', 'US')->first();

// Loop through all Official Timezones for the USA (EST, PST, CST, MST, etc.)
foreach ($country->timezones as $timezone) {
    echo $timezone->zone_name . ' (' . $timezone->abbreviation . ')' . PHP_EOL;
}

// Loop through officially accepted Currencies (e.g. Panama uses PAB and USD)
$panama = Country::where('iso2', 'PA')->first();
foreach ($panama->currencies as $currency) {
    echo $currency->code . ' - ' . $currency->symbol; 
}

use Aestheticraza\LaravelGlobe\Models\City;

$city = City::where('name', 'Karachi')->with('postalCodes')->first();

echo $city->latitude;  // 24.8607
echo $city->longitude; // 67.0011

// Fetch Postal Code arrays!
foreach($city->postalCodes as $postal) {
    echo "Area: " . $postal->area_name . " | Code: " . $postal->code;
}

'features' => [
    'enable_postal_codes' => true,
    'enable_border_currencies' => true,
    'enable_geospatial' => true,      // Disable if you don't need Lat/Lng Spatial queries
],
'performance' => [
    'cache_ttl' => 86400,             // Cache lookups for 24 hours
    'chunk_size' => 1000,             // Memory safe insertion batch size
    'nearby_default_radius' => 10,    // Default KM distance for spatial traits
],
bash
   php artisan globe:install