Download the PHP package mdhesari/laravel-cities without Composer

On this page you can find all versions of the php package mdhesari/laravel-cities. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-cities

License Downloads

Introduction

What you get:

What you dont get:

Instructions

main repository : composer require igaster/laravel_cities

current repository : composer require mdhesari/laravel-cities

The Service provider will be autodiscovered and registered by Laravel. If you are using Laravel version <5.5 then you must manually add the Service Provider in app.php:

[Tip] Quick script to download on your remote server with:

or otherwise you can use

Download a *.txt files from geonames.org By default it will download allcountries and hierarchy files otherwise you can pass flag --countries for specific countries

you can increase the memory limit for the cli invocation on demand to have process the command at once

So this will increase the memory limit for the command to 8GB with large chunk for each batches

You can also pass --chunk argument to specify how much chunk you want to process at once suppose you want 3000 records to be processed at once you can pass. This gives flexibility to make the import with low memory footprints

by default it is 1000

Note: If you don't want all the countries, you can download only country specific files (eg US.txt) and import each one of them with:

Seed with custom data

Create a json file with custom data at storage\geo and run the following command to pick a file to seed:

If an item exists in the DB (based on the 'id' value), then it will be updated else a new entry will be inserted. For example the following json file will rename United States to USA and it will add a child item (set by the parent_id value)

Please note that adding new items to the DB will reindex ALL items to rebuild the tree structure. Please be patient...

An example file is provided: countryNames.json which updates the official country names with a most popular simplified version.

Tip: You can get a json representation from the DB by quering the API (see below)

Geo Model:

You can use Mdhesari\LaravelCities\Geo Model to access the database. List of available properties:

Visit http://www.geonames.org > Info, for a more detailed description.

Usage

Searching:

Traverse tree

Check Hierarchy Relations:

Query scopes (Use them to Build custom queries)

If you need more functionality you can extend Mdhesari\LaravelCities\Geo model and add your methods.

HTTP API

This package defines some API routes that can be used to query the DB through simple HTTP requests. To use them insert in your routes file:

For example if you insert them in your routes\api.php (recomended) then the following URLs will be registered:

URL Endpoind (GET) Description Returns (JSON)
api/geo/search/{name}/{parent-id?} Search items containing 'name', (and belong to parent-id) Collection
api/geo/item/{id} Get item by id Geo
api/geo/items/{ids} Get multiple items by ids (comma seperated list) Collection
api/geo/children/{id} Get children of item Collection
api/geo/parent/{id} Get parent of item Geo
api/geo/country/{code} get country by two-letter code Geo
api/geo/countries list of countries Collection

The response is always a JSON representation of either a Geo class or a Collection.

To reduce bandwith, all Geo model attributes will be returned except from alternames, left, right and depth. You can change this behavior by passing an optional parameter on any request:

URL Params (aplly to all routes) Description Example
fields=field1,field2 Returns only the specified attributes api/geo/countries?fields=id,name
fields=all Returns all attributes api/geo/countries?fields=all

Vue Component

A Vue component is shipped with this package that plugs into the provided API and provides an interactive way to pick a location through a series of steps. Sorry, no live demo yet, just some screenshots:

Step 1: Select your location. Drop down lists loads asynchronous:

Step 2: Reached to a destination. Path is displayed and button to edit selection:

Step 3: On form submition several fields are beeing submited:

Usage Guide

Assuming that you are using Webpack to compile your assets, and you have included vue-app.js:

Add in your application

In your main vue-app.js file add the component declaration:

Vue.component('geo-select', require('RELATIVE_PATH_TO/vendor/igaster/laravel_cities/src/vue/geo-select.vue'));

Alternative you may publish the component with

artisan vendor:publish --provider="Mdhesari\LaravelCities\GeoServiceProvider"

Component will be exported at /resources/LaravelCities/geo-select.vue so that you can make modifications...

Compile compoment

npm run dev (or npm run production)

Use in blade files

Example:

The following inputs will be submited:

Full syntax:


All versions of laravel-cities with dependencies

PHP Build Version
Package Version
Requires laravel/framework Version 5.*|^6.0|7.*|8.*|9.*
mdhesari/api-response Version ^0.10
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package mdhesari/laravel-cities contains the following files

Loading the files please wait ....