Skip to content

galadrimteam/laravel-addresses

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latest Stable Version Total Downloads License

Laravel Addresses

Simple address and contact management for Laravel 5 with automatical geocoding to add longitude and latitude. Uses the famous Countries package by Webpatser.

Installation

Require the package from your composer.json file

"require": {
	"vendocrat/laravel-addresses": "dev-master"
}

and run $ composer update or both in one with $ composer require vendocrat/laravel-addresses.

Next register the following service providers and facades to your config/app.php file

'providers' => [
    // Illuminate Providers ...
    // App Providers ...
    vendocrat\Addresses\AddressesServiceProvider::class,
    Webpatser\Countries\CountriesServiceProvider::class,
];
'providers' => [
	// Illuminate Facades ...
    'Address'   => vendocrat\Addresses\Facades\Addresses::class,
    'Countries' => Webpatser\Countries\CountriesFacade::class,
];

Configuration & Migration

$ php artisan vendor:publish
$ php artisan countries:migration

This will create a config/addresses.php and the migration files. In the config file you can customize the table names, finally you'll have to run migration like so:

$ php artisan migrate

Check out Webpatser\Countries readme to see how to seed their countries data to your database.

Usage

Add an Address to a Model
$post = Post::find(1);
$post->addAddress([
    'street'     => '123 Example Drive',
    'city'       => 'Vienna',
    'post_code'  => '1110',
    'country'    => 'AT', // ISO-3166-2 or ISO-3166-3 country code
    'is_primary' => true, // optional flag
]);

Alternativly you could do...

$address = [
    'street'     => '123 Example Drive',
    'city'       => 'Vienna',
    'post_code'  => '1110',
    'country'    => 'AT', // ISO-3166-2 or ISO-3166-3 country code
    'is_primary' => true, // optional flag
];
$post->addAddress($address);

Available attributes are street, city, post_code, state, country, state, note (for internal use), is_primary, is_billing & is_shipping. Optionally you could also pass lng and lat, in case you deactivated the included geocoding functionality and want to add them yourself.

Check if Model has an Address
if ( $post->hasAddress() ) {
    // Do something
}
Get all Addresses for a Model
$addresses = $post->addresses()->get();
Get primary/billing/shipping Addresses
$address = $post->getPrimaryAddress();
$address = $post->getBillingAddress();
$address = $post->getShippingAddress();
Update an Address for a Model
$address = $post->addresses()->first(); // fetch the address

$post->updateAddress($address, $new_attributes);
Delete an Address from a Model
$address = $post->addresses()->first(); // fetch the address

$post->deleteAddress($address); // delete by passing it as argument
Delete all Addresses from a Model
$post->flushAddresses();

License

Licensed under MIT license.

Author

Handcrafted with love by Alexander Manfred Poellmann for vendocrat in Vienna & Rome.# laravel-addresses

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages