latenal/mexican-postal-codes

PostalCodes plugin for CakePHP

Installs: 194

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

Type:cakephp-plugin

1.1.1 2020-10-05 04:10 UTC

This package is auto-updated.

Last update: 2024-11-05 18:16:28 UTC


README

Installation

You can install this plugin into your CakePHP application using composer.

1. Install the plugin via composer.

Add to composer.json:

composer require latenal/mexican-postal-codes

After that, call:

composer install

2. Load plugin in cake:

bin/cake plugin load PostalCodes

3. Then, apply migrations and seeds:

bin/cake migrations migrate --plugin PostalCodes
bin/cake migrations seed --plugin PostalCodes

Usage

In your controller add:

$this->loadComponent('PostalCodes.PostalCode', []);

Get a list of states

$states = $this->PostalCode->states()->toArray();

Get a list of municipalities by state id

$state_id = 1;
$municipalities = $this->PostalCode->municipalities($state_id)->toArray();

Get a list of colonies by state id and municipality name

$state_id = 1;
$municipality = 'Álvaro Obregón';
$colonies = $this->PostalCode->colonies($state_id, $municipality)->toArray();

Get a state and municipality by postal code

$postal = '06760';
$addr = $this->PostalCode->getStateAndMuncipalityByPostalCode($postal)->first();

Get a list of colonies by postal code

$postal = '06760';
$colonies = $this->PostalCode->getColoniesByPostalCode($postal)->toArray();