latenal / mexican-postal-codes
PostalCodes plugin for CakePHP
1.1.1
2020-10-05 04:10 UTC
Requires
- php: >=7.2
- cakephp/cakephp: ^4.0
- cakephp/migrations: ^3.0
Requires (Dev)
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();