Package Data | |
---|---|
Maintainer Username: | AlexanderPoellmann |
Package Create Date: | 2015-09-22 |
Package Last Update: | 2024-04-28 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-12-14 15:07:42 |
Package Statistics | |
---|---|
Total Downloads: | 48,168 |
Monthly Downloads: | 913 |
Daily Downloads: | 15 |
Total Stars: | 197 |
Total Watchers: | 6 |
Total Forks: | 39 |
Total Open Issues: | 2 |
Simple address and contact management for Laravel 5 with automatical geocoding to add longitude and latitude. Uses the famous Countries package by Webpatser.
This package is a work in progress, please use with care and feel free to report any issues or ideas you may have!
We've transferred this package to a new owner and therefor updated the namespaces to Lecturize\Addresses. The config file is now config/lecturize.php
.
Require the package from your composer.json
file
"require": {
"lecturize/laravel-addresses": "dev-master"
}
and run $ composer update
or both in one with $ composer require lecturize/laravel-addresses
.
Next register the following service providers and facades to your config/app.php
file
'providers' => [
// Illuminate Providers ...
// App Providers ...
Lecturize\Addresses\AddressesServiceProvider::class,
Webpatser\Countries\CountriesServiceProvider::class,
];
'aliases' => [
// Illuminate Facades ...
'Countries' => Webpatser\Countries\CountriesFacade::class,
];
$ php artisan vendor:publish --provider="Webpatser\Countries\CountriesServiceProvider"
$ php artisan vendor:publish --provider="Lecturize\Addresses\AddressesServiceProvider"
This will create a config/countries.php
, a config/lecturize.php
and the migration files, that you'll have to run like so:
$ php artisan countries:migration
$ php artisan migrate
Check out Webpatser\Countries readme to see how to seed their countries data to your database.
First, add our HasAddresses
trait to your model.
<?php namespace App\Models;
use Lecturize\Addresses\Traits\HasAddresses;
class Post extends Model
{
use HasAddresses;
// ...
}
?>
$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.
if ($post->hasAddress()) {
// Do something
}
$addresses = $post->addresses()->get();
$address = $post->getPrimaryAddress();
$address = $post->getBillingAddress();
$address = $post->getShippingAddress();
$address = $post->addresses()->first(); // fetch the address
$post->updateAddress($address, $new_attributes);
$address = $post->addresses()->first(); // fetch the address
$post->deleteAddress($address); // delete by passing it as argument
$post->flushAddresses();
Licensed under MIT license.
Handcrafted with love by Alexander Manfred Poellmann in Vienna & Rome.