Package Data | |
---|---|
Maintainer Username: | craigzearfoss |
Maintainer Contact: | craigzearfoss@yahoo.com (Craig Zearfoss) |
Package Create Date: | 2016-08-15 |
Package Last Update: | 2017-01-15 |
Language: | PHP |
License: | MIT License |
Last Refreshed: | 2024-11-14 15:07:56 |
Package Statistics | |
---|---|
Total Downloads: | 7 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 1 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
This adds methods to format addresses and phone numbers to an Eloquent model in Laravel 5. It also adds geocoding functionality using GeocoderLaravel.
The AddressableTrait file is pretty simple and easy to understand so modify it to suit your needs. If you have additional functionality that you would like to see added please let me know.
It can be found on Packagist. The recommended way is through composer.
Edit composer.json
and add:
{
"require": {
"craigzearfoss/addressable-model": "dev-master"
}
}
And install dependencies:
$ composer update
If you do not have Composer installed, run these two commands:
$ curl -sS https://getcomposer.org/installer | php
$ php composer.phar install
In your model add the AddressableTrait.
<?php
// ...
use Craigzearfoss\AddressableModel\AddressableTrait;
class MyModel extends Model
{
use AddressableTrait;
The AddressableTrait assumes that your model has the following fields. You are not required to have all of the fields, only the fields that that are needed for the methods you want to use.
firstname
(string) - used by fullname
and reversename
methodslastname
(string) - used by fullname
and reversename
methodsaddress
(string)address2
(string)city
(string)state_id
(integer) - references the field abbrev
in a states
tablepostcode
(string)country_id
(integer) - references the field abbrev
in a countries
tablelat
(float) nullable - stores the latitude retrieved from GeocoderLaravellng
(float) nullable - stores the longitude retrieved from GeocoderLaravelphone
(string)fax
(string)Formatting Methods:
fullname
reversename
formattedAddress
formattedPhone
formattedFax
Geocoder Methods
fetchGeocode
- returns the geocode array for the current recordfetchCoordinates
- returns an array with the latitude and longitude for the current recordupdateGeocode
- updates the lat
and lng
fields for the current modellookupGeocode
- makes a call to Google maps for the specified address and return the geocode arrayloopupCoordinates
- makes a call to Google maps for the specified address and returns an array with the latitude and longitudedistance
- calculates the distance between the current record and the specified latitude and longitudescopeDistance
- adds a location coordinate and distance to a queryPlease open an issue on GitHub
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
AddressableModel is released under the MIT License. See the bundled LICENSE file for details.