PHP code example of codeheures / laravel-utils

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

    

codeheures / laravel-utils example snippets


$ip = "82.246.117.210"
if(filter_var($ip, FILTER_VALIDATE_IP)) {
            try {
                    [
                        'all_infos' => Codeheures\LaravelUtils\Traits\Geo\GeoUtils::getGeoByIp($ip),
                        'loc_infos' => Codeheures\LaravelUtils\Traits\Geo\GeoUtils::getGeoLocByIp($ip),
                        'country_info' => Codeheures\LaravelUtils\Traits\Geo\GeoUtils::getCountryByIp($ip)
                    ]
            } catch(...) { ...}
}            

//result example
[
    'all_infos' => ["ip"=>"82.246.117.210","city"=>"Joué-lès-Tours","region"=>"Centre","country"=>"FR","loc"=>"47.3522,0.6691","postal"=>"37300"],
    'loc_infos' => ["47.3522","0.6691"],
    'country_info' => "FR"
]

$ip = Codeheures\LaravelUtils\Traits\Tools\Ip::getNonPrivateIpByRequest($request)); 

//result example
"82.246.117.210"

$ip = Codeheures\LaravelUtils\Traits\Tools\Ip::getNonPrivateIpByRequest($request, '82.246.117.210')); 

//result example
"82.246.117.210"

$browser = Codeheures\LaravelUtils\Traits\Tools\Browser::getBrowserName(); 

//result example
"chrome"

$listEnumValues = Codeheures\LaravelUtils\Traits\Tools\Database::getEnumValues('priceTable','currencies');

//result example
['dollard', 'euro', 'yen', 'bitcoins']

Codeheures\LaravelUtils\Traits\Tools\Database::getCountItems('customer',['name'=>'paul', 'age'=>'18']); 

//result example
172

Codeheures\LaravelUtils\Traits\Tools\Locale::listLocales();

//result example
[    "af" => [
        "code" => "af",
        "name" => "afrikaans",
        "region" => ""
      ],
      "af_NA" => [
        "code" => "af_NA",
        "name" => "afrikaans (Namibie)",
        "region" => "namibie"
      ],
      ...
]      

Codeheures\LaravelUtils\Traits\Tools\Locale::listLocales();

//result example
[       
       "en" => [
         "code" => "en",
         "name" => "anglais",
         "region" => ""
       ]
       "en_001" => [
         "code" => "en_001",
         "name" => "anglais (Monde)",
         "region" => "monde"
       ]
       "en_150" => [
         "code" => "en_150",
         "name" => "anglais (Europe)",
         "region" => "europe"
       ]     
      ...
]     

Codeheures\LaravelUtils\Traits\Tools\Locale::existLocale('fr_FR');

//result example
true

Codeheures\LaravelUtils\Traits\Tools\Locale::isValidLocale('fr_FR');

//result example
"fr_FR"

Codeheures\LaravelUtils\Traits\Tools\Locale::getFirstLocaleByCountryCode('ca');

//result example
"en_CA"

Codeheures\LaravelUtils\Traits\Tools\Locale::composeLocale('fr', 'CA');

//result example
"fr_CA"

Codeheures\LaravelUtils\Traits\Tools\Locale::getDefaultLocale();

//result example
"en_US"

Codeheures\LaravelUtils\Traits\Tools\Currencies::isAvailableCurrency("EUR")

//result example
true

Codeheures\LaravelUtils\Traits\Tools\Currencies::getSubUnit("EUR")

//result example
2

Codeheures\LaravelUtils\Traits\Tools\Currencies::listCurrencies("fr_CA")

//result example
[
    "XAF" => [
      "code" => "XAF",
      "symbol" => "XAF",
      "subunit" => 0
    ],
    "CAD" => [
      "code" => "CAD",
      "symbol" => "$",
      "subunit" => 2
    ],
    ...
]    

Codeheures\LaravelUtils\Traits\Tools\Currencies::getSymbolByCurrencyCode("CAD", "fr)

//result example
"$CA" 

Codeheures\LaravelUtils\Traits\Tools\Currencies::getDefaultMoneyByComposeLocale("fr_CA", "EUR")

//result example
"CAD" 

Codeheures\LaravelUtils\Traits\Tools\Locale::getDefaultCurrency();

//result example
"EUR"

config('runtime.ip') //your public Ip or fallback ip (see above PHP Tool: Get valid public IP)
config('runtime.locale') //the RuntimeLocale middlware look for the best local and assign to this
config('runtime.currency') //the RuntimeLocale middlware look for the best currecny and assign to this

    php artisan vendor:publish --provider="Codeheures\LaravelUtils\LaravelUtilsServiceProvider"