Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

igaster's avatar
Level 11

[Package] Countries & Cities

Hello!

I've just released a new package igaster/laravel_cities that wraps geoname.org database (ex MaxCDN). You can deploy your DB localy and query for any city on the world (or limit to a specific country)

A short example:

// Get the States of USA in aplhabetic order
geo::getCountry('US')
    ->children()
    ->orderBy('name')
    ->get();

// Get the 3 biggest cities of Greece
geo::getCountry('GR')
    ->level(geo::LEVEL_3)
    ->orderBy('population','DESC')
    ->limit(3)
    ->get();

What you get:

  • Deploy and use geonames.org (ex MaxCDN) database localy to query countries/citiew
  • Get information like lattitude/longtityde, population etc
  • Optimized DB tree structure for searching and traversing the tree.
  • Provides an Eloquent model (geo) with multiple query-scopes to help you build your queries.
  • Exposes a simple API that you can use to create AJAX calls. (Eg search while typing etc).

What you dont get:

  • geoIP & Postalcodes (not included in free sets)
  • Map elements smaller than "3rd Administration Division" (=Cities)
0 likes
2 replies
stevenbauman's avatar

First thing, in my opinion, you should be using Pascal Casing:

http://wiki.c2.com/?PascalCase

Your package has mixed casing (snake & camel casing).

I wouldn't use this package for various reasons, but first and foremost this doesn't look pretty and align with Laravel's design (or PSR). For example:

use igaster\laravel_cities\geo;

Should be:

use Igaster\LaravelCities\Geo;

Geo::getCountry('GR');

Some other issues:

  • Tons of raw SQL in your parseGeoFile.php (shouldn't need this, Laravel has a built in ORM)
  • Random commented code
  • Long functions that should be split into multiple
  • Classes in use that aren't imported

I would read PSR (PHP Standards Recommendations): http://www.php-fig.org/psr/

igaster's avatar
Level 11

@stevenbauman Thank you for reviewing. I've released a new version with Laravel coding styles applied as you recomended. Now it is:

use Igaster\LaravelCities\Geo;

In fact I started this package while experimenting with various geo-providers. I decided to ship it as a Package when I saw that I couldn't find this functionality on Laravel. This is the reason that the Seeder is written in plain PHP. My aim was to provide an efficient way to query geographical data in a tree-like structure.

For exapmle when the user selects a country (eg with select2.js) you can dynamically load the provinces and then the cities step-by-step.

Maybe I will release some vue templates that plug with the API to provide a complete solution.

Thank you for your recomendations!

Please or to participate in this conversation.