Skip to content
This repository has been archived by the owner on Feb 16, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/v0.0.2'
Browse files Browse the repository at this point in the history
* release/v0.0.2: (65 commits)
  Rename package rinvex/addresses from rinvex/addressable
  Rename package rinvex/addresses from rinvex/addressable
  Update composer dependencies
  Disable travis email notifications
  Enforce consistency
  Simplify installation steps by removing optional low-priority steps
  Apply fixes from StyleCI
  Override ValidatingTrait
  Program to an interface not implementation for flexible model swapping
  Update models docblock
  Tweak service provider and enforce consistency
  Bind model alias into IoC container
  Apply fixes from StyleCI
  Use IoC bound model instead of the explicitly hardcoded
  Fix config & migration paths
  Fix migration path
  Fix wrong config path
  Fix wrong namespace
  Enforce consistency
  Enforce consistent namespaces
  ...
  • Loading branch information
Omranic committed Sep 8, 2017
2 parents 54d5e33 + 7c9ee89 commit c3fa535
Show file tree
Hide file tree
Showing 17 changed files with 632 additions and 531 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -21,6 +21,7 @@ after_script:
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover

notifications:
email: false
slack:
rooms:
- secure: 9aO2+TMXt8CwXfF5j5MUI5edHBTny5LXSWZq2kCCJPmIFk9b/4k0zvtmfSG4xNA3SDLX6xHOZRATeJPgk35jIyTBNDwfO5IM15/DvndQMHJWvT9AH6kOKITpSstf2gB6cORlH2NYTsFs8mVuvC84FgZLXS2zv22zIXAsZ6frZuTh75KPG9OEQOjrnSD2unGWLG2L0iYKBaDnpo4GURTkr0zSXM8zfGIdQopSzs2/ouSnc6+m5D4YdDtynmF7fRUWbOX2EbzeAKynY7fx+fsk0UoQ/bAJuG6zKMDmXFpZSzvei/A/W4BQFyUvmye+9X+yu+apiH3uRRj1eVeZJXTX4APo5aTAgNyBLYUMVk+nItJzVgJqOXBTv1ML/emRY1GWcbl5SW3diSdU6OkAtOAJF+N72diGI4KIrBRSUmVYWWou7YD2naG/r3NCgpc88L5X1GBbv8Q70yrkMpqQFPjhWjWcDRnfR1z5KP8lpbErsrU3VuE9Ev6KffA7AxORxn5txsxw/6N52NDzP+jfTaCPtNrD6RyWBpgW7CCM6BC2YGTz23i82PTPWSQqJeUCnLfNW7fN98LM0LqFiFOgMiYTLWA47QlawgBDKHPCnuAjlVJrq7feiLF2DuP4bandBovDuxoQuXCFpGkui+yX+qtbsQEEOd1YaXCHmlBmsnAa7iM=
8 changes: 7 additions & 1 deletion CHANGELOG.md
@@ -1,9 +1,15 @@
# Rinvex Addressable Change Log
# Rinvex Addresses Change Log

All notable changes to this project will be documented in this file.

This project adheres to [Semantic Versioning](CONTRIBUTING.md).


## [v0.0.2] - 2017-09-08
- Fix many issues and apply many enhancements
- Rename package rinvex/addresses from rinvex/addressable

## v0.0.1 - 2017-04-07
- Commit first draft

[v0.0.2]: https://github.com/rinvex/addresses/compare/v0.0.1...v0.0.2
144 changes: 39 additions & 105 deletions README.md
@@ -1,58 +1,43 @@
# Rinvex Addressable
# Rinvex Addresses

**Rinvex Addressable** is a polymorphic Laravel package, for addressbook management. You can add addresses to any eloquent model with ease.
**Rinvex Addresses** is a polymorphic Laravel package, for addressbook management. You can add addresses to any eloquent model with ease.

[![Packagist](https://img.shields.io/packagist/v/rinvex/addressable.svg?label=Packagist&style=flat-square)](https://packagist.org/packages/rinvex/addressable)
[![VersionEye Dependencies](https://img.shields.io/versioneye/d/php/rinvex:addressable.svg?label=Dependencies&style=flat-square)](https://www.versioneye.com/php/rinvex:addressable/)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/rinvex/addressable.svg?label=Scrutinizer&style=flat-square)](https://scrutinizer-ci.com/g/rinvex/addressable/)
[![Code Climate](https://img.shields.io/codeclimate/github/rinvex/addressable.svg?label=CodeClimate&style=flat-square)](https://codeclimate.com/github/rinvex/addressable)
[![Travis](https://img.shields.io/travis/rinvex/addressable.svg?label=TravisCI&style=flat-square)](https://travis-ci.org/rinvex/addressable)
[![Packagist](https://img.shields.io/packagist/v/rinvex/addresses.svg?label=Packagist&style=flat-square)](https://packagist.org/packages/rinvex/addresses)
[![VersionEye Dependencies](https://img.shields.io/versioneye/d/php/rinvex:addresses.svg?label=Dependencies&style=flat-square)](https://www.versioneye.com/php/rinvex:addresses/)
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/rinvex/addresses.svg?label=Scrutinizer&style=flat-square)](https://scrutinizer-ci.com/g/rinvex/addresses/)
[![Code Climate](https://img.shields.io/codeclimate/github/rinvex/addresses.svg?label=CodeClimate&style=flat-square)](https://codeclimate.com/github/rinvex/addresses)
[![Travis](https://img.shields.io/travis/rinvex/addresses.svg?label=TravisCI&style=flat-square)](https://travis-ci.org/rinvex/addresses)
[![SensioLabs Insight](https://img.shields.io/sensiolabs/i/8a185d9d-f23a-4782-b71c-aa35ee74d385.svg?label=SensioLabs&style=flat-square)](https://insight.sensiolabs.com/projects/8a185d9d-f23a-4782-b71c-aa35ee74d385)
[![StyleCI](https://styleci.io/repos/87485079/shield)](https://styleci.io/repos/87485079)
[![License](https://img.shields.io/packagist/l/rinvex/addressable.svg?label=License&style=flat-square)](https://github.com/rinvex/addressable/blob/develop/LICENSE)
[![License](https://img.shields.io/packagist/l/rinvex/addresses.svg?label=License&style=flat-square)](https://github.com/rinvex/addresses/blob/develop/LICENSE)


## Installation

1. Install the package via composer:
```shell
composer require rinvex/addressable
composer require rinvex/addresses
```

2. Execute migrations via the following command:
```
php artisan migrate --path="vendor/rinvex/addressable/database/migrations"
php artisan rinvex:migrate:addresses
```

3. Add the following service provider to the `'providers'` array inside `app/config/app.php`:
```php
Rinvex\Addressable\AddressableServiceProvider::class
```

4. **Optionally** you can publish migration and config files by running the following commands:
```shell
// Publish migrations
php artisan vendor:publish --tag="migrations" --provider="Rinvex\Addressable\AddressableServiceProvider"

// Publish config
php artisan vendor:publish --tag="config" --provider="Rinvex\Addressable\AddressableServiceProvider"
```

5. Done!
3. Done!


## Usage

### Create Your Model

Simply create a new eloquent model, and use `Addressable` trait:
``` php
<?php
Simply create a new eloquent model, and use `\Rinvex\Addresses\Traits\Addressable` trait:

namespace App;
```php
namespace App\Models;

use Rinvex\Addressable\Addressable;
use Illuminate\Database\Eloquent\Model;
use Rinvex\Addresses\Traits\Addressable;

class User extends Model
{
Expand All @@ -63,134 +48,83 @@ class User extends Model
### Manage Your Addresses

```php
use Rinvex\Addressable\Address;
$user = new \App\Models\User();

// Create a new address
Address::create([
$user->addresses()->create([
'label' => 'Default Address',
'name_prefix' => 'Mr.',
'first_name' => 'Abdelrahman',
'middle_name' => 'Hossam M. M.',
'last_name' => 'Omran',
'name_suffix' => null,
'country' => 'eg',
'organization' => 'Rinvex',
'country_code' => 'eg',
'street' => '56 john doe st.',
'state' => 'Alexandria',
'city' => 'Alexandria',
'useral_code' => '21614',
'phone' => '01228160181',
'lat' => '31.2467601',
'lng' => '29.9020376',
'is_primary' => true,
'is_billing' => true,
'is_shipping' => true,
]);

// Find an existing address
$address = Address::find(1);

// Update an existing address
$address->update([
'label' => 'Default Work Address',
]);
```

### Alternative Method to Manage Your Addresses

```php
use App\User;
use Rinvex\Addressable\Address;

// Find an existing user
$user = User::find(1);

// Create a new address
$user->createAddress([
'label' => 'Default Address',
'name_prefix' => 'Mr.',
'first_name' => 'Abdelrahman',
'middle_name' => 'Hossam M. M.',
'last_name' => 'Omran',
'name_suffix' => null,
'country' => 'eg',
'organization' => 'Rinvex',
'street' => '56 john doe st.',
'state' => 'Alexandria',
'city' => 'Alexandria',
'useral_code' => '21614',
'phone' => '01228160181',
'lat' => '31.2467601',
'lng' => '29.9020376',
'is_primary' => true,
'is_billing' => true,
'is_shipping' => true,
// Create multiple new addresses
$user->addresses()->createMany([
[...],
[...],
[...],
]);

// Find an existing address
$address = Address::find(1);
$address = app('rinvex.addresses.address')->find(1);

// Update an existing address
$user->updateAddress($address, [
$address->update([
'label' => 'Default Work Address',
]);

// Attach an existing address
$user->attachAddress($address);

// Attach multiple existing addresses
$user->attachAddress([1, 2, 3]);

// Detach an existing address
$user->detachAddress($address);

// Attach multiple existing addresses
$user->detachAddress([1, 2, 3]);
// Delete address
$address->delete();

// Alternative method for detaching addresses
$user->removeAddress($address);
$user->removeAddress([1, 2, 3]);
// Alternative way of address deletion
$user->addresses()->where('id', 123)->first()->delete();
```

### Manage Your Addressable Model

The API is intutive and very straightfarwad, so let's give it a quick look:

```php
// Instantiate your model
$user = new \App\User();
$user = new \App\Models\User();

// Get attached addresses collection
$user->addresses;

// Get attached addresses query builder
$user->addresses();
```

### Advanced Usage

```php
// Scope Primary Addresses
Address::isPrimary();
$primaryAddresses = app('rinvex.addresses.address')->isPrimary()->get();

// Scope Billing Addresses
Address::isBilling();
$billingAddresses = app('rinvex.addresses.address')->isBilling()->get();

// Scope Shipping Addresses
Address::isShipping();
$shippingAddresses = app('rinvex.addresses.address')->isShipping()->get();

// Scope Addresses in the given country
Address::InCountry('eg');

// Retrieve All Models Attached To The Address
$address = Address::find(1);
$address->entries(\App\User::class);
$egyptianAddresses = app('rinvex.addresses.address')->InCountry('eg')->get();

// Find all users within 5 kilometers radius from the lat/lng 31.2467601/29.9020376
User::findByDistance(5, 'kilometers', '31.2467601', '29.9020376');
$fiveKmAddresses = \App\Models\User::findByDistance(5, 'kilometers', '31.2467601', '29.9020376')->get();

// Alternative method to find users with certain radius
$user = new User();
$users = $location->lat('31.2467601')->lng('29.9020376')->within(5, 'kilometers')->get();
// Alternative method to find users within certain radius
$user = new \App\Models\User();
$users = $user->lat('31.2467601')->lng('29.9020376')->within(5, 'kilometers')->get();
```


Expand Down
39 changes: 26 additions & 13 deletions composer.json
@@ -1,26 +1,32 @@
{
"name": "rinvex/addressable",
"description": "Rinvex Addressable is a polymorphic Laravel package, for addressbook management. You can add addresses to any eloquent model with ease.",
"name": "rinvex/addresses",
"description": "Rinvex Addresses is a polymorphic Laravel package, for addressbook management. You can add addresses to any eloquent model with ease.",
"keywords": [
"city",
"state",
"model",
"postal",
"rinvex",
"street",
"address",
"laravel",
"country",
"primary",
"billing",
"shipping",
"eloquent",
"latitude",
"longitude",
"addressable",
"polymorphic"
],
"license": "MIT",
"homepage": "https://rinvex.com",
"support": {
"email": "help@rinvex.com",
"issues": "https://github.com/rinvex/addressable/issues",
"source": "https://github.com/rinvex/addressable",
"docs": "https://github.com/rinvex/addressable/blob/master/README.md"
"issues": "https://github.com/rinvex/addresses/issues",
"source": "https://github.com/rinvex/addresses",
"docs": "https://github.com/rinvex/addresses/blob/master/README.md"
},
"authors": [
{
Expand All @@ -36,39 +42,46 @@
},
{
"name": "The Generous Laravel Community",
"homepage": "https://github.com/rinvex/addressable/contributors"
"homepage": "https://github.com/rinvex/addresses/contributors"
}
],
"require": {
"php": "^7.0.0",
"jackpopp/geodistance": "^1.2",
"illuminate/support": "~5.4.0",
"illuminate/database": "~5.4.0",
"illuminate/support": "~5.5.0",
"illuminate/database": "~5.5.0",
"rinvex/cacheable": "dev-develop"
},
"require-dev": {
"phpunit/phpunit": "^5.7.0",
"illuminate/container": "~5.4.0"
"phpunit/phpunit": "^6.0.0",
"illuminate/container": "~5.5.0"
},
"autoload": {
"classmap": [
"database"
],
"psr-4": {
"Rinvex\\Addressable\\": "src/"
"Rinvex\\Addresses\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Rinvex\\Addressable\\Test\\": "tests"
"Rinvex\\Addresses\\Test\\": "tests"
}
},
"config": {
"sort-packages": true
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true
},
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"laravel": {
"providers": [
"Rinvex\\Addresses\\Providers\\AddressesServiceProvider"
]
}
},
"minimum-stability": "dev",
Expand Down
25 changes: 6 additions & 19 deletions config/config.php
Expand Up @@ -4,30 +4,17 @@

return [

/*
|--------------------------------------------------------------------------
| Addressable Database Tables
|--------------------------------------------------------------------------
|
| Specify database table names that should be used to
| store your data. You may use whatever you like.
|
*/


// Addresses Database Tables
'tables' => [

'addresses' => 'addresses',
'addressables' => 'addressables',

],

/*
|--------------------------------------------------------------------------
| Addressable Geocoding Options
|--------------------------------------------------------------------------
*/
// Addresses Models
'models' => [
'address' => \Rinvex\Addresses\Models\Address::class,
],

// Addresses Geocoding Options
'geocoding' => false,

];

0 comments on commit c3fa535

Please sign in to comment.