PHPackages                             codeheures/laravel-utils - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. codeheures/laravel-utils

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

codeheures/laravel-utils
========================

Utility for Laravel 5.4

v1.2(8y ago)149MITPHPPHP &gt;=7.0.0

Since Mar 31Pushed 8y ago1 watchersCompare

[ Source](https://github.com/CODEheures/laravelUtils)[ Packagist](https://packagist.org/packages/codeheures/laravel-utils)[ Docs](http://github.com/codeheures/laravelUtils)[ RSS](/packages/codeheures-laravel-utils/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependenciesVersions (20)Used By (0)

laravel-utils
=============

[](#laravel-utils)

Laravel-utils is a toolbox that allow:

- API to get geolocation informations of client by ip. Usable for server-side processing
- PHP tool to get a valid public IP (useful on a devel environment)
- PHP tool to get browser infos
- PHP tool to get database enum list, or get count items with a reusable mutiple where (=) clause
- Middleware to to share config('runtime.ip') variable (base on PHP tool to get valid public IP)
- Middleware to obtain automatically the best locale for your client and share it on your application by a config('runtime.locale') variable. You can use {lang} for route param to force set locale
- Middleware to obtain automatically the best currency for your client and share it on your application by a config('runtime.currency') variable

API: Geolocation Informations by Ip
-----------------------------------

[](#api-geolocation-informations-by-ip)

This API allow you to serve geolocation infos to client (useful for xhtmlrequests).
You can also use static function for a server side processing.

### Get complete informations

[](#get-complete-informations)

with Ip on URL

```
http://yourproject/geoIp/geoByIp/82.246.117.210

```

```
//result example
{"ip":"82.246.117.210","city":"Joué-lès-Tours","region":"Centre","country":"FR","loc":"47.3522,0.6691","postal":"37300"}
```

without Ip : try first to use your public Ip. If not public, try to use config('codeheuresUtils.ipTest'). If not available Ip finally use a static IP

```
http://yourproject/geoIp/geoByIp

```

```
//result example
{"ip":"82.246.117.210","city":"Joué-lès-Tours","region":"Centre","country":"FR","loc":"47.3522,0.6691","postal":"37300"}
```

### Get only LOC \[latitutde, longitude\] informations

[](#get-only-loc-latitutde-longitude-informations)

With or without IP on url (see above)

```
http://yourproject/geoIp/geoLocByIp

```

```
//result example
["47.3522","0.6691"]
```

### Get only Country informations

[](#get-only-country-informations)

With or without IP on url (see above)

```
http://yourproject/geoIp/countryByIp

```

```
//result example
"FR"
```

### If error

[](#if-error)

```
//result example
{"error":"unknow IP"}
```

PHP Tool: Geolocation Informations by Ip
----------------------------------------

[](#php-tool-geolocation-informations-by-ip)

### You can use statics class for a side-server processing

[](#you-can-use-statics-class-for-a-side-server-processing)

```
$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"
]
```

PHP Tool: Get valid public IP
-----------------------------

[](#php-tool-get-valid-public-ip)

with only request: return your IP if public or the static class var Ip

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

```
//result example
"82.246.117.210"
```

with a second param: return your IP if public, or param if public IP, or finally the static class var Ip

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

```
//result example
"82.246.117.210"
```

PHP Tool: Get the Browser Name
------------------------------

[](#php-tool-get-the-browser-name)

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

```
//result example
"chrome"
```

PHP Tool: Get Database Infos
----------------------------

[](#php-tool-get-database-infos)

### get list of enum values for a column of a table

[](#get-list-of-enum-values-for-a-column-of-a-table)

Example: get the enum values of the currencies column of the priceTable

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

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

### get easy count elem on a table with multiple count where

[](#get-easy-count-elem-on-a-table-with-multiple-count-where)

The where clauses is a equal clauses

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

```
//result example
172
```

PHP Tool: Locale Tools
----------------------

[](#php-tool-locale-tools)

Locale Tools allow you to obtain various information of locales. This suite of tools is used in a powerful middleware to find the best locale adapted to the user. When the middleware find the best locale, this is shared in a config('runtime.locale') variable accessible throughout the application. You can use it to translate your application for the user.

### Array of locales availables on the server

[](#array-of-locales-availables-on-the-server)

without restriction of availables languages (find in codeheuresUtils.availableLocales config file):

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

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

with restriction:

```
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"
       ]
      ...
]
```

### Boolean test if a locale is an available locale

[](#boolean-test-if-a-locale-is-an-available-locale)

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

```
//result example
true
```

### Test if a locale is an valid locale and return locale or null

[](#test-if-a-locale-is-an-valid-locale-and-return-locale-or-null)

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

```
//result example
"fr_FR"
```

### Get the first possible locale by a country code

[](#get-the-first-possible-locale-by-a-country-code)

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

```
//result example
"en_CA"
```

### Compose a locale and return if exist, null if don't exist

[](#compose-a-locale-and-return-if-exist-null-if-dont-exist)

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

```
//result example
"fr_CA"
```

### Get default Locale within env('DEFAULT\_LOCALE') or static var $last\_fall\_locale

[](#get-default-locale-within-envdefault_locale-or-static-var-last_fall_locale)

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

```
//result example
"en_US"
```

PHP Tool: Currencies Tools
--------------------------

[](#php-tool-currencies-tools)

Currencies Tools allow you to obtain various information of currencies. It use MoneyPhp and config('runtime.locale') This suite of tools is used in a powerful middleware to find the best currency adapted to the user. When the middleware find the best currency, this is shared in a config('runtime.currency') variable accessible throughout the application. You can use it to manage prices in your application.

### Test if a currency exist

[](#test-if-a-currency-exist)

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

```
//result example
true
```

### Get subunit of a currency (if exist else return 0)

[](#get-subunit-of-a-currency-if-exist-else-return-0)

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

```
//result example
2
```

### Get list of currencies with symbol according to a locale

[](#get-list-of-currencies-with-symbol-according-to-a-locale)

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

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

### Get symbol by currency code and locale

[](#get-symbol-by-currency-code-and-locale)

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

```
//result example
"$CA"
```

### Get default money by a compose local (the second param is a fallback currency)

[](#get-default-money-by-a-compose-local-the-second-param-is-a-fallback-currency)

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

```
//result example
"CAD"
```

### Get default Currency within env('DEFAULT\_CURRENCY') or static var $last\_fall\_currency

[](#get-default-currency-within-envdefault_currency-or-static-var-last_fall_currency)

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

```
//result example
"EUR"
```

Middleware: config('runtime.ip'), config('runtime.locale') &amp; config('runtime.currency')
-------------------------------------------------------------------------------------------

[](#middleware-configruntimeip-configruntimelocale--configruntimecurrency)

Installation of middlawares allow you to use config('runtime.ip'), config('runtime.locale') &amp; config('runtime.currency') all over the application controllers ans views.

config('runtime.locale') &amp; config('runtime.currency') can be saved and read in User attribute 'locale' &amp; 'currency'

```
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
```

Installation
============

[](#installation)

- Add laravel-utils to your composer.json file to require laravel-utils :

```
    require : {
        "laravel/framework": "5.4.*",
        "codeheures/laravel-utils": "^1.0"
    }

```

- Update Composer :

```
    composer update

```

- add the service provider to config/app.php :

```
    Codeheures\LaravelUtils\LaravelUtilsServiceProvider::class,

```

- add middlewares to web routes in app/Http/kernel.php (respect order IP-&gt;Locale-&gt;Currency). Middleware SetLocaleByRuntime is optionnal and allow you to set your app locale automatically base on the detect best locale.:

```
protected $middlewareGroups = [
        'web' => [
            ...
            \Codeheures\LaravelUtils\Http\Middleware\RuntimeIp::class,
            \Codeheures\LaravelUtils\Http\Middleware\RuntimeLocale::class,
            \Codeheures\LaravelUtils\Http\Middleware\RuntimeCurrency::class,
            \Codeheures\LaravelUtils\Http\Middleware\SetLocaleByRuntime::class, //optionnal
        ],

```

- Publish the config file config/codeheuresUtils.php:

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

```

In config file you can change

- routes uri,
- routes names
- routes middlwares (Add a admin type middleware to refreshDb is highly advised)
- value of Ip test
- list of availables locales

Optionnal: add "locale" and/or "currency" attribute to User to manage saving preferences locale in your app

### Before first use we update maxmind db

[](#before-first-use-we-update-maxmind-db)

```
    http://yourproject/geoIp/refreshDb

```

Congratulations, you have successfully installed laravel-utils !

### Copyright and Licence

[](#copyright-and-licence)

This product includes GeoLite2 data created by MaxMind, available from [](http://www.maxmind.com).

This product use GeoIp2 on apache2 Licence [](https://github.com/maxmind/GeoIP2-php).

This product use Moneyphp on MIT Licence [](https://github.com/moneyphp/money).

This software is provided "as is" without warranty of any kind, either express or implied, regarding the software package, its merchantability, or its fitness for any particular purpose.

This is free software, licensed under the Apache License, Version 2.0.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community1

Small or concentrated contributor base

Maturity67

Established project with proven stability

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~17 days

Recently: every ~66 days

Total

19

Last Release

3013d ago

PHP version history (2 changes)v1.1.0PHP &gt;=5.4.0

v1.2PHP &gt;=7.0.0

### Community

### Embed Badge

![Health badge](/badges/codeheures-laravel-utils/health.svg)

```
[![Health](https://phpackages.com/badges/codeheures-laravel-utils/health.svg)](https://phpackages.com/packages/codeheures-laravel-utils)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
