From bfec3cf98d36500cccfe073f559fba36d3e65b1e Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 7 Apr 2017 00:12:38 +0000 Subject: [PATCH 01/65] Apply fixes from StyleCI --- config/config.php | 1 - .../migrations/2017_03_31_005125_create_addresses_table.php | 1 + src/Address.php | 4 ++-- src/Addressable.php | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/config.php b/config/config.php index 117fa8f..faf9eb3 100644 --- a/config/config.php +++ b/config/config.php @@ -14,7 +14,6 @@ | */ - 'tables' => [ 'addresses' => 'addresses', diff --git a/database/migrations/2017_03_31_005125_create_addresses_table.php b/database/migrations/2017_03_31_005125_create_addresses_table.php index a9f7e19..46d1097 100755 --- a/database/migrations/2017_03_31_005125_create_addresses_table.php +++ b/database/migrations/2017_03_31_005125_create_addresses_table.php @@ -1,5 +1,6 @@ firstOrCreate($attributes); + $addressInstance = (new $addressModel())->firstOrCreate($attributes); $this->addresses()->syncWithoutDetaching($addressInstance); } @@ -99,7 +99,7 @@ public function addAddress(array $attributes) public function updateAddress($address, array $attributes) { $addressModel = static::getAddressClassName(); - $addressInstance = $address instanceof Model ? $address : (new $addressModel)->findOrFail($address); + $addressInstance = $address instanceof Model ? $address : (new $addressModel())->findOrFail($address); $addressInstance->update($attributes); $this->addresses()->syncWithoutDetaching($addressInstance); } From 86ff4766d8cec6bd21eaeeba85284374d7c7d969 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 7 Apr 2017 03:59:23 +0200 Subject: [PATCH 02/65] Enforce naming consistency via renaming country to country_code --- README.md | 4 ++-- .../2017_03_31_005125_create_addresses_table.php | 2 +- src/Address.php | 10 +++++----- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a15ed0e..0714f08 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Address::create([ 'middle_name' => 'Hossam M. M.', 'last_name' => 'Omran', 'name_suffix' => null, - 'country' => 'eg', + 'country_code' => 'eg', 'organization' => 'Rinvex', 'street' => '56 john doe st.', 'state' => 'Alexandria', @@ -113,7 +113,7 @@ $user->createAddress([ 'middle_name' => 'Hossam M. M.', 'last_name' => 'Omran', 'name_suffix' => null, - 'country' => 'eg', + 'country_code' => 'eg', 'organization' => 'Rinvex', 'street' => '56 john doe st.', 'state' => 'Alexandria', diff --git a/database/migrations/2017_03_31_005125_create_addresses_table.php b/database/migrations/2017_03_31_005125_create_addresses_table.php index 46d1097..b4b409a 100755 --- a/database/migrations/2017_03_31_005125_create_addresses_table.php +++ b/database/migrations/2017_03_31_005125_create_addresses_table.php @@ -18,7 +18,7 @@ public function up() $table->string('middle_name')->nullable(); $table->string('last_name')->nullable(); $table->string('name_suffix')->nullable(); - $table->string('country', 2)->nullable(); + $table->string('country_code', 2)->nullable(); $table->string('organization')->nullable(); $table->string('street')->nullable(); $table->string('state')->nullable(); diff --git a/src/Address.php b/src/Address.php index 461e8de..11746bb 100755 --- a/src/Address.php +++ b/src/Address.php @@ -25,7 +25,7 @@ class Address extends Model 'middle_name', 'last_name', 'name_suffix', - 'country', + 'country_code', 'organization', 'street', 'state', @@ -91,13 +91,13 @@ public function createAddress(Builder $query): Builder * Scope addresses by given country. * * @param \Illuminate\Database\Eloquent\Builder $query - * @param string|null $country + * @param string|null $countryCode * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeInCountry(Builder $query, string $country = null): Builder + public function scopeInCountry(Builder $query, string $countryCode = null): Builder { - return $country ? $query->where('country', $country) : $query; + return $countryCode ? $query->where('country_code', $countryCode) : $query; } /** @@ -111,7 +111,7 @@ public static function boot(): void if (config('rinvex.addressable.geocoding')) { $segments[] = $address->street; $segments[] = sprintf('%s, %s %s', $address->city, $address->state, $address->postal_code); - $segments[] = country($address->country)->getName(); + $segments[] = country($address->country_code)->getName(); $query = str_replace(' ', '+', implode(', ', $segments)); $geocode = json_decode(file_get_contents("https://maps.google.com/maps/api/geocode/json?address={$query}&sensor=false")); From f9efae165ce552d867255b60dbad68475f83a66d Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 7 Apr 2017 04:00:00 +0200 Subject: [PATCH 03/65] Drop phone field from address records - is phone really related?! Don't think so.. --- README.md | 1 - database/migrations/2017_03_31_005125_create_addresses_table.php | 1 - src/Address.php | 1 - 3 files changed, 3 deletions(-) diff --git a/README.md b/README.md index 0714f08..d245e6d 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,6 @@ Address::create([ 'state' => 'Alexandria', 'city' => 'Alexandria', 'useral_code' => '21614', - 'phone' => '01228160181', 'lat' => '31.2467601', 'lng' => '29.9020376', 'is_primary' => true, diff --git a/database/migrations/2017_03_31_005125_create_addresses_table.php b/database/migrations/2017_03_31_005125_create_addresses_table.php index b4b409a..d9d506d 100755 --- a/database/migrations/2017_03_31_005125_create_addresses_table.php +++ b/database/migrations/2017_03_31_005125_create_addresses_table.php @@ -24,7 +24,6 @@ public function up() $table->string('state')->nullable(); $table->string('city')->nullable(); $table->string('postal_code')->nullable(); - $table->string('phone')->nullable(); $table->float('lat')->nullable(); $table->float('lng')->nullable(); $table->boolean('is_primary')->default(false); diff --git a/src/Address.php b/src/Address.php index 11746bb..cfa7e14 100755 --- a/src/Address.php +++ b/src/Address.php @@ -31,7 +31,6 @@ class Address extends Model 'state', 'city', 'postal_code', - 'phone', 'lat', 'lng', 'is_primary', From d874ad7521ca1ca8db7fb7fada3ffc9796edd41c Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 7 Apr 2017 21:31:30 +0200 Subject: [PATCH 04/65] Rename country field to country_code for naming consistency --- README.md | 4 ++-- .../migrations/2017_03_31_005125_create_addresses_table.php | 2 +- src/Address.php | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d245e6d..df26947 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,8 @@ Address::create([ 'middle_name' => 'Hossam M. M.', 'last_name' => 'Omran', 'name_suffix' => null, - 'country_code' => 'eg', 'organization' => 'Rinvex', + 'country_code' => 'eg', 'street' => '56 john doe st.', 'state' => 'Alexandria', 'city' => 'Alexandria', @@ -112,8 +112,8 @@ $user->createAddress([ 'middle_name' => 'Hossam M. M.', 'last_name' => 'Omran', 'name_suffix' => null, - 'country_code' => 'eg', 'organization' => 'Rinvex', + 'country_code' => 'eg', 'street' => '56 john doe st.', 'state' => 'Alexandria', 'city' => 'Alexandria', diff --git a/database/migrations/2017_03_31_005125_create_addresses_table.php b/database/migrations/2017_03_31_005125_create_addresses_table.php index d9d506d..dd37977 100755 --- a/database/migrations/2017_03_31_005125_create_addresses_table.php +++ b/database/migrations/2017_03_31_005125_create_addresses_table.php @@ -18,8 +18,8 @@ public function up() $table->string('middle_name')->nullable(); $table->string('last_name')->nullable(); $table->string('name_suffix')->nullable(); - $table->string('country_code', 2)->nullable(); $table->string('organization')->nullable(); + $table->string('country_code', 2)->nullable(); $table->string('street')->nullable(); $table->string('state')->nullable(); $table->string('city')->nullable(); diff --git a/src/Address.php b/src/Address.php index cfa7e14..0a2ffd3 100755 --- a/src/Address.php +++ b/src/Address.php @@ -25,8 +25,8 @@ class Address extends Model 'middle_name', 'last_name', 'name_suffix', - 'country_code', 'organization', + 'country_code', 'street', 'state', 'city', @@ -87,7 +87,7 @@ public function createAddress(Builder $query): Builder } /** - * Scope addresses by given country. + * Scope addresses by the given country. * * @param \Illuminate\Database\Eloquent\Builder $query * @param string|null $countryCode From 43ef8455127a305c4a1e0ac1c5ef22dbde9648f6 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 11 Apr 2017 05:26:54 +0200 Subject: [PATCH 05/65] Update docblock --- src/Addressable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Addressable.php b/src/Addressable.php index ea2505c..aedd2a7 100755 --- a/src/Addressable.php +++ b/src/Addressable.php @@ -63,7 +63,7 @@ public function addresses(): MorphToMany } /** - * Boot Addressable trait. + * Boot the addressable trait for a model. * * @return void */ @@ -105,7 +105,7 @@ public function updateAddress($address, array $attributes) } /** - * Attach the given address(es) to the addressable model. + * Attach the given address to the addressable model. * * @param mixed $address * From b2b2c3e5f5ee48faa3b7887abd719b4e4e9ec855 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 11 Apr 2017 05:27:41 +0200 Subject: [PATCH 06/65] Fix wrong relations deletion/detaching method --- src/Addressable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Addressable.php b/src/Addressable.php index aedd2a7..3e9a520 100755 --- a/src/Addressable.php +++ b/src/Addressable.php @@ -70,7 +70,7 @@ public function addresses(): MorphToMany public static function bootAddressable() { static::deleted(function (Model $addressableModel) { - $addressableModel->addresses()->delete(); + $addressableModel->addresses()->detach(); }); } From 2e1de44a58f0f60f0ba4f85552429ae58cd3cb5c Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 11 Apr 2017 05:33:40 +0200 Subject: [PATCH 07/65] Enforce consistent naming convensions --- README.md | 13 ++++++++----- src/Addressable.php | 22 +++++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index df26947..71e6019 100644 --- a/README.md +++ b/README.md @@ -135,16 +135,19 @@ $user->updateAddress($address, [ ]); // Attach an existing address -$user->attachAddress($address); +$user->attachAddresses($addresses); // Attach multiple existing addresses -$user->attachAddress([1, 2, 3]); +$user->attachAddresses([1, 2, 3]); // Detach an existing address -$user->detachAddress($address); +$user->detachAddresses($address); -// Attach multiple existing addresses -$user->detachAddress([1, 2, 3]); +// Detach multiple existing addresses +$user->detachAddresses([1, 2, 3]); + +// Detach all existing addresses +$user->detachAddresses(); // Alternative method for detaching addresses $user->removeAddress($address); diff --git a/src/Addressable.php b/src/Addressable.php index 3e9a520..60c3edf 100755 --- a/src/Addressable.php +++ b/src/Addressable.php @@ -105,39 +105,39 @@ public function updateAddress($address, array $attributes) } /** - * Attach the given address to the addressable model. + * Attach the given address(s) to the addressable model. * - * @param mixed $address + * @param mixed $addresses * * @return void */ - public function attachAddress($addresses) + public function attachAddresses($addresses) { $this->addresses()->syncWithoutDetaching($addresses); } /** - * Remove the given address from the addressable model. + * Remove the given address(s) from the addressable model. * - * @param mixed $address + * @param mixed $addresses * * @return void */ - public function detachAddress($address) + public function detachAddresses($addresses = null) { - $this->addresses()->detach($address); + $this->addresses()->detach($addresses); } /** - * Remove the given address from the addressable model. + * Remove the given address(s) from the addressable model. * - * @param mixed $address + * @param mixed $addresses * * @return void */ - public function removeAddress($address) + public function removeAddresses($addresses = null) { - $this->detachAddress($address); + $this->detachAddress($addresses); } /** From 9d4cc2b8ea858a5ad3b4df23aeaee645f5f7fbcb Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 27 Apr 2017 15:12:59 +0300 Subject: [PATCH 08/65] Add country accessor for address model --- src/Address.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Address.php b/src/Address.php index 0a2ffd3..9a93b20 100755 --- a/src/Address.php +++ b/src/Address.php @@ -122,4 +122,16 @@ public static function boot(): void } }); } + + /** + * Get the address' country. + * + * @param string $countryCode + * + * @return \Rinvex\Country\Country + */ + public function getCountryAttribute(string $countryCode) + { + return country($countryCode); + } } From b953d56a846fadb54a36149265fa4e84d4ad7cfe Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 28 Apr 2017 16:07:56 +0300 Subject: [PATCH 09/65] Fix country accessor --- src/Address.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Address.php b/src/Address.php index 9a93b20..9ac507d 100755 --- a/src/Address.php +++ b/src/Address.php @@ -126,12 +126,10 @@ public static function boot(): void /** * Get the address' country. * - * @param string $countryCode - * * @return \Rinvex\Country\Country */ - public function getCountryAttribute(string $countryCode) + public function getCountryAttribute() { - return country($countryCode); + return country($this->country_code); } } From c07a7061386052295cb40afa09f427cc407a90de Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 2 May 2017 13:37:57 +0200 Subject: [PATCH 10/65] Update address model class docblock --- src/Address.php | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/Address.php b/src/Address.php index 9ac507d..cce0912 100755 --- a/src/Address.php +++ b/src/Address.php @@ -10,6 +10,58 @@ use Jackpopp\GeoDistance\GeoDistanceTrait; use Illuminate\Database\Eloquent\Relations\MorphToMany; +/** + * Rinvex\Addressable\Address + * + * @property int $id + * @property string $label + * @property string $name_prefix + * @property string $first_name + * @property string $middle_name + * @property string $last_name + * @property string $name_suffix + * @property string $organization + * @property string $country_code + * @property string $street + * @property string $state + * @property string $city + * @property string $postal_code + * @property float $lat + * @property float $lng + * @property bool $is_primary + * @property bool $is_billing + * @property bool $is_shipping + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property string $deleted_at + * @property-read \Rinvex\Country\Country $country + * + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address inCountry($countryCode = null) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address isBilling() + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address isPrimary() + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereCity($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereCountryCode($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereDeletedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereFirstName($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereIsBilling($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereIsPrimary($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereIsShipping($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereLabel($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereLastName($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereLat($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereLng($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereMiddleName($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereNamePrefix($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereNameSuffix($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereOrganization($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address wherePostalCode($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereState($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereStreet($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereUpdatedAt($value) + * @mixin \Eloquent + */ class Address extends Model { use GeoDistanceTrait; From a8733898d1bab25d6e9748191a8f32828bec28cf Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 2 May 2017 15:25:42 +0000 Subject: [PATCH 11/65] Apply fixes from StyleCI --- src/Address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Address.php b/src/Address.php index cce0912..9b9a233 100755 --- a/src/Address.php +++ b/src/Address.php @@ -11,7 +11,7 @@ use Illuminate\Database\Eloquent\Relations\MorphToMany; /** - * Rinvex\Addressable\Address + * Rinvex\Addressable\Address. * * @property int $id * @property string $label From fde6bc30828f72bb85d4ff9fe98de63641afde11 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 26 May 2017 04:48:21 +0200 Subject: [PATCH 12/65] Enforce consistency --- .../2017_03_31_031227_create_addressables_table.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/database/migrations/2017_03_31_031227_create_addressables_table.php b/database/migrations/2017_03_31_031227_create_addressables_table.php index f11b9e2..6459052 100644 --- a/database/migrations/2017_03_31_031227_create_addressables_table.php +++ b/database/migrations/2017_03_31_031227_create_addressables_table.php @@ -17,8 +17,8 @@ public function up() { Schema::create(config('rinvex.addressable.tables.addressables'), function (Blueprint $table) { // Columns - $table->unsignedInteger('address_id'); - $table->unsignedInteger('addressable_id'); + $table->integer('address_id')->unsigned(); + $table->integer('addressable_id')->unsigned(); $table->string('addressable_type'); $table->timestamps(); From b365193caadfbd2e904deb2131a0d9dbbe6059cb Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sun, 4 Jun 2017 15:45:13 +0200 Subject: [PATCH 13/65] Add Laravel 5.5 support --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 612270e..ebfc444 100755 --- a/composer.json +++ b/composer.json @@ -42,13 +42,13 @@ "require": { "php": "^7.0.0", "jackpopp/geodistance": "^1.2", - "illuminate/support": "~5.4.0", - "illuminate/database": "~5.4.0", + "illuminate/support": "~5.4.0|~5.5.0", + "illuminate/database": "~5.4.0|~5.5.0", "rinvex/cacheable": "dev-develop" }, "require-dev": { "phpunit/phpunit": "^5.7.0", - "illuminate/container": "~5.4.0" + "illuminate/container": "~5.4.0|~5.5.0" }, "autoload": { "classmap": [ From f8167f8e9f808b731b6a4ef77f52efa1a803df0f Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sun, 4 Jun 2017 15:49:14 +0200 Subject: [PATCH 14/65] Replace hardcoded table name --- .../migrations/2017_03_31_031227_create_addressables_table.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/database/migrations/2017_03_31_031227_create_addressables_table.php b/database/migrations/2017_03_31_031227_create_addressables_table.php index 6459052..f14a220 100644 --- a/database/migrations/2017_03_31_031227_create_addressables_table.php +++ b/database/migrations/2017_03_31_031227_create_addressables_table.php @@ -24,7 +24,7 @@ public function up() // Indexes $table->unique(['address_id', 'addressable_id', 'addressable_type'], 'addressables_ids_type_unique'); - $table->foreign('address_id')->references('id')->on('addresses') + $table->foreign('address_id')->references('id')->on(config('rinvex.addressable.tables.addresses')) ->onDelete('cascade')->onUpdate('cascade'); }); } From c951ecb8859989511b83002ca83857200826a852 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 6 Jun 2017 16:36:14 +0200 Subject: [PATCH 15/65] Enforce consistency --- src/AddressableServiceProvider.php | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/AddressableServiceProvider.php b/src/AddressableServiceProvider.php index ae4cef5..32d89ec 100644 --- a/src/AddressableServiceProvider.php +++ b/src/AddressableServiceProvider.php @@ -39,13 +39,9 @@ public function boot() protected function publishResources() { // Publish config - $this->publishes([ - realpath(__DIR__.'/../config/config.php') => config_path('rinvex.addressable.php'), - ], 'config'); + $this->publishes([realpath(__DIR__.'/../config/config.php') => config_path('rinvex.addressable.php')], 'config'); // Publish migrations - $this->publishes([ - realpath(__DIR__.'/../database/migrations') => database_path('migrations'), - ], 'migrations'); + $this->publishes([realpath(__DIR__.'/../database/migrations') => database_path('migrations')], 'migrations'); } } From bf847c55d5a095fafbb0550a3fe370afb7a2407c Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 13 Jun 2017 00:08:47 +0200 Subject: [PATCH 16/65] Support Auto-Discovery --- composer.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/composer.json b/composer.json index ebfc444..415dd0b 100755 --- a/composer.json +++ b/composer.json @@ -69,6 +69,11 @@ "extra": { "branch-alias": { "dev-master": "1.0-dev" + }, + "laravel": { + "providers": [ + "Rinvex\\Addressable\\AddressableServiceProvider" + ] } }, "minimum-stability": "dev", From 07598d5fc2337e02ac65badda72339b76d54ac3e Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 13 Jun 2017 01:32:12 +0200 Subject: [PATCH 17/65] Push forward PHPUnit version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 415dd0b..407381d 100755 --- a/composer.json +++ b/composer.json @@ -47,7 +47,7 @@ "rinvex/cacheable": "dev-develop" }, "require-dev": { - "phpunit/phpunit": "^5.7.0", + "phpunit/phpunit": "^6.0.0", "illuminate/container": "~5.4.0|~5.5.0" }, "autoload": { From 87c74f68b1130710f186806f109b775c1bf0a15c Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Mon, 19 Jun 2017 16:59:36 +0200 Subject: [PATCH 18/65] Fix model boot method signature --- src/Address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Address.php b/src/Address.php index 9b9a233..cda2390 100755 --- a/src/Address.php +++ b/src/Address.php @@ -154,7 +154,7 @@ public function scopeInCountry(Builder $query, string $countryCode = null): Buil /** * {@inheritdoc} */ - public static function boot(): void + protected static function boot() { parent::boot(); From e5201e1fe508688c0b68de06e68f8193dd108001 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 29 Jun 2017 04:20:32 +0200 Subject: [PATCH 19/65] Update composer config --- composer.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 407381d..481775d 100755 --- a/composer.json +++ b/composer.json @@ -64,7 +64,9 @@ } }, "config": { - "sort-packages": true + "preferred-install": "dist", + "sort-packages": true, + "optimize-autoloader": true }, "extra": { "branch-alias": { From 339f633e3dc39d6664c6b3222b838e039f16895b Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 8 Jul 2017 08:20:04 +0200 Subject: [PATCH 20/65] Enforce readme consistency and readability --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 71e6019..a2751f1 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ 3. Add the following service provider to the `'providers'` array inside `app/config/app.php`: ```php - Rinvex\Addressable\AddressableServiceProvider::class + Rinvex\Addressable\AddressableServiceProvider::class, ``` 4. **Optionally** you can publish migration and config files by running the following commands: @@ -46,9 +46,7 @@ ### Create Your Model Simply create a new eloquent model, and use `Addressable` trait: -``` php - Date: Sat, 8 Jul 2017 08:26:15 +0200 Subject: [PATCH 21/65] Enforce attribute casting --- src/Address.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/Address.php b/src/Address.php index cda2390..d4c9205 100755 --- a/src/Address.php +++ b/src/Address.php @@ -90,6 +90,30 @@ class Address extends Model 'is_shipping', ]; + /** + * {@inheritdoc} + */ + protected $casts = [ + 'label' => 'string', + 'name_prefix' => 'string', + 'first_name' => 'string', + 'middle_name' => 'string', + 'last_name' => 'string', + 'name_suffix' => 'string', + 'organization' => 'string', + 'country_code' => 'string', + 'street' => 'string', + 'state' => 'string', + 'city' => 'string', + 'postal_code' => 'string', + 'lat' => 'float', + 'lng' => 'float', + 'is_primary' => 'boolean', + 'is_billing' => 'boolean', + 'is_shipping' => 'boolean', + 'deleted_at' => 'datetime', + ]; + /** * Get all attached models of the given class to the address. * From 42fcb8971499eaa3b606ec3a6ba77eaef8654a25 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 8 Jul 2017 08:31:44 +0200 Subject: [PATCH 22/65] Enforce validation rules --- src/Address.php | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/Address.php b/src/Address.php index d4c9205..7f50aa0 100755 --- a/src/Address.php +++ b/src/Address.php @@ -4,6 +4,7 @@ namespace Rinvex\Addressable; +use Watson\Validating\ValidatingTrait; use Illuminate\Database\Eloquent\Model; use Rinvex\Cacheable\CacheableEloquent; use Illuminate\Database\Eloquent\Builder; @@ -64,6 +65,7 @@ */ class Address extends Model { + use ValidatingTrait; use GeoDistanceTrait; use CacheableEloquent; @@ -114,6 +116,60 @@ class Address extends Model 'deleted_at' => 'datetime', ]; + /** + * {@inheritdoc} + */ + protected $observables = [ + 'validating', + 'validated', + ]; + + /** + * The default rules that the model will validate against. + * + * @var array + */ + protected $rules = []; + + /** + * Whether the model should throw a + * ValidationException if it fails validation. + * + * @var bool + */ + protected $throwValidationExceptions = true; + + /** + * Create a new Eloquent model instance. + * + * @param array $attributes + */ + public function __construct(array $attributes = []) + { + parent::__construct($attributes); + + $this->setTable(config('rinvex.addressable.tables.addresses')); + $this->setRules([ + 'label' => 'required|integer|exists:'.config('rinvex.addressable.tables.resources').',id', + 'name_prefix' => 'nullable|string|max:150', + 'first_name' => 'nullable|string|max:150', + 'middle_name' => 'nullable|string|max:150', + 'last_name' => 'nullable|string|max:150', + 'name_suffix' => 'nullable|string|max:150', + 'organization' => 'nullable|string|max:150', + 'country_code' => 'nullable|alpha|size:2|country', + 'street' => 'nullable|string|max:150', + 'state' => 'nullable|string|max:150', + 'city' => 'nullable|string|max:150', + 'postal_code' => 'nullable|string|max:150', + 'lat' => 'nullable|numeric', + 'lng' => 'nullable|numeric', + 'is_primary' => 'boolean', + 'is_billing' => 'boolean', + 'is_shipping' => 'boolean', + ]); + } + /** * Get all attached models of the given class to the address. * From 071c8d6aaa178e5a237f76542b4e9e901b0cd9ef Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 8 Jul 2017 08:37:00 +0200 Subject: [PATCH 23/65] Enforce eloquent builder usage consistency --- src/Address.php | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Address.php b/src/Address.php index 7f50aa0..afd600e 100755 --- a/src/Address.php +++ b/src/Address.php @@ -185,50 +185,50 @@ public function entries(string $class): MorphToMany /** * Scope primary addresses. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $builder * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeIsPrimary(Builder $query): Builder + public function scopeIsPrimary(Builder $builder): Builder { - return $query->where('is_primary', true); + return $builder->where('is_primary', true); } /** * Scope billing addresses. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $builder * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeIsBilling(Builder $query): Builder + public function scopeIsBilling(Builder $builder): Builder { - return $query->where('is_billing', true); + return $builder->where('is_billing', true); } /** * Scope shipping addresses. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $builder * * @return \Illuminate\Database\Eloquent\Builder */ - public function createAddress(Builder $query): Builder + public function createAddress(Builder $builder): Builder { - return $query->where('is_shipping', true); + return $builder->where('is_shipping', true); } /** * Scope addresses by the given country. * - * @param \Illuminate\Database\Eloquent\Builder $query + * @param \Illuminate\Database\Eloquent\Builder $builder * @param string|null $countryCode * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeInCountry(Builder $query, string $countryCode = null): Builder + public function scopeInCountry(Builder $builder, string $countryCode = null): Builder { - return $countryCode ? $query->where('country_code', $countryCode) : $query; + return $countryCode ? $builder->where('country_code', $countryCode) : $builder; } /** From 330a73787751b0ac9b0d30e92320e7facdd7696c Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 8 Jul 2017 15:39:12 +0200 Subject: [PATCH 24/65] Call fill->save() rather than create() for explicit calls --- src/Addressable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Addressable.php b/src/Addressable.php index 60c3edf..06f7c47 100755 --- a/src/Addressable.php +++ b/src/Addressable.php @@ -100,7 +100,7 @@ public function updateAddress($address, array $attributes) { $addressModel = static::getAddressClassName(); $addressInstance = $address instanceof Model ? $address : (new $addressModel())->findOrFail($address); - $addressInstance->update($attributes); + $addressInstance->fill($attributes)->save(); $this->addresses()->syncWithoutDetaching($addressInstance); } From 7e7b4bcdacbfdb8feb44af5403454b3f04002d83 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 15 Jul 2017 21:31:02 +0200 Subject: [PATCH 25/65] Tag published resources --- README.md | 6 +++--- src/AddressableServiceProvider.php | 7 ++----- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a2751f1..d93d116 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,13 @@ Rinvex\Addressable\AddressableServiceProvider::class, ``` -4. **Optionally** you can publish migration and config files by running the following commands: +4. **Optionally** you can publish migrations and config files by running the following commands: ```shell // Publish migrations - php artisan vendor:publish --tag="migrations" --provider="Rinvex\Addressable\AddressableServiceProvider" + php artisan vendor:publish --tag="rinvex-addressable-migrations" // Publish config - php artisan vendor:publish --tag="config" --provider="Rinvex\Addressable\AddressableServiceProvider" + php artisan vendor:publish --tag="rinvex-addressable-config" ``` 5. Done! diff --git a/src/AddressableServiceProvider.php b/src/AddressableServiceProvider.php index 32d89ec..01a63e8 100644 --- a/src/AddressableServiceProvider.php +++ b/src/AddressableServiceProvider.php @@ -38,10 +38,7 @@ public function boot() */ protected function publishResources() { - // Publish config - $this->publishes([realpath(__DIR__.'/../config/config.php') => config_path('rinvex.addressable.php')], 'config'); - - // Publish migrations - $this->publishes([realpath(__DIR__.'/../database/migrations') => database_path('migrations')], 'migrations'); + $this->publishes([realpath(__DIR__.'/../config/config.php') => config_path('rinvex.addressable.php')], 'rinvex-addressable-config'); + $this->publishes([realpath(__DIR__.'/../database/migrations') => database_path('migrations')], 'rinvex-addressable-migrations'); } } From 53a507f3c21cbd0f0628f77122ba3d7f0240a38f Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 15 Jul 2017 21:33:19 +0200 Subject: [PATCH 26/65] Convert addressables to Polymorphic Relations from Many To Many Polymorphic Relations --- config/config.php | 26 +++----- ...17_03_31_005125_create_addresses_table.php | 5 ++ ...03_31_031227_create_addressables_table.php | 41 ------------- src/Address.php | 18 +++--- src/Addressable.php | 61 ++++++------------- 5 files changed, 44 insertions(+), 107 deletions(-) delete mode 100644 database/migrations/2017_03_31_031227_create_addressables_table.php diff --git a/config/config.php b/config/config.php index faf9eb3..c6b4abc 100644 --- a/config/config.php +++ b/config/config.php @@ -2,31 +2,21 @@ declare(strict_types=1); -return [ +use Rinvex\Addressable\Address; - /* - |-------------------------------------------------------------------------- - | Addressable Database Tables - |-------------------------------------------------------------------------- - | - | Specify database table names that should be used to - | store your data. You may use whatever you like. - | - */ +return [ + // Addressable Database Tables 'tables' => [ - 'addresses' => 'addresses', - 'addressables' => 'addressables', - ], - /* - |-------------------------------------------------------------------------- - | Addressable Geocoding Options - |-------------------------------------------------------------------------- - */ + // Addressable Models + 'models' => [ + 'address' => Address::class, + ], + // Addressable Geocoding Options 'geocoding' => false, ]; diff --git a/database/migrations/2017_03_31_005125_create_addresses_table.php b/database/migrations/2017_03_31_005125_create_addresses_table.php index dd37977..7bf217c 100755 --- a/database/migrations/2017_03_31_005125_create_addresses_table.php +++ b/database/migrations/2017_03_31_005125_create_addresses_table.php @@ -12,6 +12,8 @@ public function up() Schema::create(config('rinvex.addressable.tables.addresses'), function (Blueprint $table) { // Columns $table->increments('id'); + $table->integer('addressable_id')->unsigned(); + $table->string('addressable_type'); $table->string('label')->nullable(); $table->string('name_prefix')->nullable(); $table->string('first_name')->nullable(); @@ -31,6 +33,9 @@ public function up() $table->boolean('is_shipping')->default(false); $table->timestamps(); $table->softDeletes(); + + // Indexes + $table->unique(['addressable_id', 'addressable_type'], 'addressables_id_type_unique'); }); } diff --git a/database/migrations/2017_03_31_031227_create_addressables_table.php b/database/migrations/2017_03_31_031227_create_addressables_table.php deleted file mode 100644 index f14a220..0000000 --- a/database/migrations/2017_03_31_031227_create_addressables_table.php +++ /dev/null @@ -1,41 +0,0 @@ -integer('address_id')->unsigned(); - $table->integer('addressable_id')->unsigned(); - $table->string('addressable_type'); - $table->timestamps(); - - // Indexes - $table->unique(['address_id', 'addressable_id', 'addressable_type'], 'addressables_ids_type_unique'); - $table->foreign('address_id')->references('id')->on(config('rinvex.addressable.tables.addresses')) - ->onDelete('cascade')->onUpdate('cascade'); - }); - } - - /** - * Reverse the migrations. - * - * @return void - */ - public function down() - { - Schema::dropIfExists(config('rinvex.addressable.tables.addressables')); - } -} diff --git a/src/Address.php b/src/Address.php index afd600e..82dd5f7 100755 --- a/src/Address.php +++ b/src/Address.php @@ -9,7 +9,7 @@ use Rinvex\Cacheable\CacheableEloquent; use Illuminate\Database\Eloquent\Builder; use Jackpopp\GeoDistance\GeoDistanceTrait; -use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Illuminate\Database\Eloquent\Relations\MorphTo; /** * Rinvex\Addressable\Address. @@ -73,6 +73,8 @@ class Address extends Model * {@inheritdoc} */ protected $fillable = [ + 'addressable_id', + 'addressable_type', 'label', 'name_prefix', 'first_name', @@ -96,6 +98,8 @@ class Address extends Model * {@inheritdoc} */ protected $casts = [ + 'addressable_id' => 'integer', + 'addressable_type' => 'string', 'label' => 'string', 'name_prefix' => 'string', 'first_name' => 'string', @@ -150,6 +154,8 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.addressable.tables.addresses')); $this->setRules([ + 'addressable_id' => 'required|integer', + 'addressable_type' => 'nullable|string|max:150', 'label' => 'required|integer|exists:'.config('rinvex.addressable.tables.resources').',id', 'name_prefix' => 'nullable|string|max:150', 'first_name' => 'nullable|string|max:150', @@ -171,15 +177,13 @@ public function __construct(array $attributes = []) } /** - * Get all attached models of the given class to the address. + * Get the owner model of the address. * - * @param string $class - * - * @return \Illuminate\Database\Eloquent\Relations\MorphToMany + * @return \Illuminate\Database\Eloquent\Relations\MorphTo */ - public function entries(string $class): MorphToMany + public function addressable(): MorphTo { - return $this->morphedByMany($class, 'addressable', config('rinvex.addressable.tables.addressables'), 'address_id', 'addressable_id'); + return $this->morphTo(); } /** diff --git a/src/Addressable.php b/src/Addressable.php index 06f7c47..18455c5 100755 --- a/src/Addressable.php +++ b/src/Addressable.php @@ -6,19 +6,10 @@ use Illuminate\Support\Collection; use Illuminate\Database\Eloquent\Model; -use Illuminate\Database\Eloquent\Relations\MorphToMany; +use Illuminate\Database\Eloquent\Relations\MorphMany; trait Addressable { - /** - * Register a created model event with the dispatcher. - * - * @param \Closure|string $callback - * - * @return void - */ - abstract public static function created($callback); - /** * Register a deleted model event with the dispatcher. * @@ -29,37 +20,26 @@ abstract public static function created($callback); abstract public static function deleted($callback); /** - * Define a polymorphic many-to-many relationship. + * Define a polymorphic one-to-many relationship. * - * @param string $related - * @param string $name - * @param string|null $table - * @param string|null $foreignKey - * @param string|null $otherKey - * @param bool $inverse + * @param string $related + * @param string $name + * @param string $type + * @param string $id + * @param string $localKey * - * @return \Illuminate\Database\Eloquent\Relations\MorphToMany + * @return \Illuminate\Database\Eloquent\Relations\MorphMany */ - abstract public function morphToMany($related, $name, $table = null, $foreignKey = null, $otherKey = null, $inverse = false); - - /** - * Get address class name. - * - * @return string - */ - public static function getAddressClassName(): string - { - return Address::class; - } + abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null); /** * Get all attached addresses to the model. * - * @return \Illuminate\Database\Eloquent\Relations\MorphToMany + * @return \Illuminate\Database\Eloquent\Relations\MorphMany */ - public function addresses(): MorphToMany + public function addresses(): MorphMany { - return $this->morphToMany(static::getAddressClassName(), 'addressable', config('rinvex.addressable.tables.addressables'), 'addressable_id', 'address_id')->withTimestamps(); + return $this->morphMany(config('rinvex.addressable.models.address'), 'addressable'); } /** @@ -83,7 +63,7 @@ public static function bootAddressable() */ public function addAddress(array $attributes) { - $addressModel = static::getAddressClassName(); + $addressModel = config('rinvex.addressable.models.address'); $addressInstance = (new $addressModel())->firstOrCreate($attributes); $this->addresses()->syncWithoutDetaching($addressInstance); } @@ -91,17 +71,15 @@ public function addAddress(array $attributes) /** * Update the given address and attach to the addressable model. * - * @param int|\Illuminate\Database\Eloquent\Model $address - * @param array $attributes + * @param \Illuminate\Database\Eloquent\Model $address + * @param array $attributes * * @return void */ - public function updateAddress($address, array $attributes) + public function updateAddress(Model $address, array $attributes) { - $addressModel = static::getAddressClassName(); - $addressInstance = $address instanceof Model ? $address : (new $addressModel())->findOrFail($address); - $addressInstance->fill($attributes)->save(); - $this->addresses()->syncWithoutDetaching($addressInstance); + $address->fill($attributes)->save(); + $this->addresses()->syncWithoutDetaching($address); } /** @@ -152,7 +130,8 @@ public function removeAddresses($addresses = null) */ public static function findByDistance($distance, $unit, $lat, $lng): Collection { - $records = Address::within($distance, $unit, $lat, $lng)->get(); + $addressModel = config('rinvex.addressable.models.address'); + $records = (new $addressModel)->within($distance, $unit, $lat, $lng)->get(); $results = []; foreach ($records as $record) { From 12eab40c1fb65b3e2dcd38753f4f4c24a41057f6 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sun, 16 Jul 2017 05:33:19 +0200 Subject: [PATCH 27/65] Tweak readme code samples --- README.md | 70 +++++++++++++++++++------------------------------------ 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/README.md b/README.md index d93d116..acf9bfa 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Simply create a new eloquent model, and use `Addressable` trait: ```php -namespace App; +namespace App\Models; use Rinvex\Addressable\Addressable; use Illuminate\Database\Eloquent\Model; @@ -61,10 +61,10 @@ 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', @@ -84,25 +84,7 @@ Address::create([ '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 +// Alternative way of contact create $user->createAddress([ 'label' => 'Default Address', 'name_prefix' => 'Mr.', @@ -116,7 +98,6 @@ $user->createAddress([ 'state' => 'Alexandria', 'city' => 'Alexandria', 'useral_code' => '21614', - 'phone' => '01228160181', 'lat' => '31.2467601', 'lng' => '29.9020376', 'is_primary' => true, @@ -125,23 +106,28 @@ $user->createAddress([ ]); // Find an existing address -$address = Address::find(1); +$address = \Rinvex\Addressable\Address::find(1); // Update an existing address +$address->update([ + 'label' => 'Default Work Address', +]); + +// Alternative way of address update $user->updateAddress($address, [ 'label' => 'Default Work Address', ]); -// Attach an existing address -$user->attachAddresses($addresses); +// Attach existing address +$user->attachAddresses($address); -// Attach multiple existing addresses +// Attach existing addresses $user->attachAddresses([1, 2, 3]); -// Detach an existing address +// Detach existing address $user->detachAddresses($address); -// Detach multiple existing addresses +// Detach existing addresses $user->detachAddresses([1, 2, 3]); // Detach all existing addresses @@ -157,40 +143,32 @@ $user->removeAddress([1, 2, 3]); 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 = \Rinvex\Addressable\Address::isPrimary(); // Scope Billing Addresses -Address::isBilling(); +$billingAddresses = \Rinvex\Addressable\Address::isBilling(); // Scope Shipping Addresses -Address::isShipping(); +$shippingAddresses = \Rinvex\Addressable\Address::isShipping(); // 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 = \Rinvex\Addressable\Address::InCountry('eg'); // 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'); -// 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(); ``` From 759e75594d8cfc6e49890c2aeb8630d3e2a5b979 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sun, 16 Jul 2017 03:33:31 +0000 Subject: [PATCH 28/65] Apply fixes from StyleCI --- src/Addressable.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Addressable.php b/src/Addressable.php index 18455c5..8659287 100755 --- a/src/Addressable.php +++ b/src/Addressable.php @@ -22,11 +22,11 @@ abstract public static function deleted($callback); /** * Define a polymorphic one-to-many relationship. * - * @param string $related - * @param string $name - * @param string $type - * @param string $id - * @param string $localKey + * @param string $related + * @param string $name + * @param string $type + * @param string $id + * @param string $localKey * * @return \Illuminate\Database\Eloquent\Relations\MorphMany */ @@ -131,7 +131,7 @@ public function removeAddresses($addresses = null) public static function findByDistance($distance, $unit, $lat, $lng): Collection { $addressModel = config('rinvex.addressable.models.address'); - $records = (new $addressModel)->within($distance, $unit, $lat, $lng)->get(); + $records = (new $addressModel())->within($distance, $unit, $lat, $lng)->get(); $results = []; foreach ($records as $record) { From a83f2ea59f616dcf8fd2e20e1e9da01a7fadc4a4 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 18 Jul 2017 03:34:46 +0200 Subject: [PATCH 29/65] Drop Laravel 5.4 support --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 481775d..584c133 100755 --- a/composer.json +++ b/composer.json @@ -42,13 +42,13 @@ "require": { "php": "^7.0.0", "jackpopp/geodistance": "^1.2", - "illuminate/support": "~5.4.0|~5.5.0", - "illuminate/database": "~5.4.0|~5.5.0", + "illuminate/support": "~5.5.0", + "illuminate/database": "~5.5.0", "rinvex/cacheable": "dev-develop" }, "require-dev": { "phpunit/phpunit": "^6.0.0", - "illuminate/container": "~5.4.0|~5.5.0" + "illuminate/container": "~5.5.0" }, "autoload": { "classmap": [ From 695f793489eaa0ff1aa9c2ac549955fd51ecbf2a Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 18 Jul 2017 03:35:40 +0200 Subject: [PATCH 30/65] Fix deprecated PHPUnit TestCase namespace --- tests/ServiceProviderTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index e3f6bd9..1ec654a 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -5,12 +5,12 @@ namespace Rinvex\Addressable\Test; use ReflectionClass; -use PHPUnit_Framework_TestCase; +use PHPUnit\Framework\TestCase; use Illuminate\Container\Container; use Illuminate\Support\ServiceProvider; use Rinvex\Addressable\AddressableServiceProvider; -class ServiceProviderTest extends PHPUnit_Framework_TestCase +class ServiceProviderTest extends TestCase { /** Get the service provider class. */ protected function getServiceProviderClass(): string From 405deace0bb3963f2e3cfa111cecbec4f55e3f8f Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 02:58:38 +0200 Subject: [PATCH 31/65] Drop wrong table index --- .../migrations/2017_03_31_005125_create_addresses_table.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/database/migrations/2017_03_31_005125_create_addresses_table.php b/database/migrations/2017_03_31_005125_create_addresses_table.php index 7bf217c..ddb5712 100755 --- a/database/migrations/2017_03_31_005125_create_addresses_table.php +++ b/database/migrations/2017_03_31_005125_create_addresses_table.php @@ -33,9 +33,6 @@ public function up() $table->boolean('is_shipping')->default(false); $table->timestamps(); $table->softDeletes(); - - // Indexes - $table->unique(['addressable_id', 'addressable_type'], 'addressables_id_type_unique'); }); } From 3ac3c64537567f0705dd918aedb4ef023e72e4f8 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 02:58:56 +0200 Subject: [PATCH 32/65] Drop soft deletes timestamp --- database/migrations/2017_03_31_005125_create_addresses_table.php | 1 - 1 file changed, 1 deletion(-) diff --git a/database/migrations/2017_03_31_005125_create_addresses_table.php b/database/migrations/2017_03_31_005125_create_addresses_table.php index ddb5712..718b8cf 100755 --- a/database/migrations/2017_03_31_005125_create_addresses_table.php +++ b/database/migrations/2017_03_31_005125_create_addresses_table.php @@ -32,7 +32,6 @@ public function up() $table->boolean('is_billing')->default(false); $table->boolean('is_shipping')->default(false); $table->timestamps(); - $table->softDeletes(); }); } From 2564ec99725b821708511379f2022d71f864b032 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 02:59:12 +0200 Subject: [PATCH 33/65] Enforce consistent morph table schema --- .../migrations/2017_03_31_005125_create_addresses_table.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/database/migrations/2017_03_31_005125_create_addresses_table.php b/database/migrations/2017_03_31_005125_create_addresses_table.php index 718b8cf..7fc6b94 100755 --- a/database/migrations/2017_03_31_005125_create_addresses_table.php +++ b/database/migrations/2017_03_31_005125_create_addresses_table.php @@ -12,8 +12,7 @@ public function up() Schema::create(config('rinvex.addressable.tables.addresses'), function (Blueprint $table) { // Columns $table->increments('id'); - $table->integer('addressable_id')->unsigned(); - $table->string('addressable_type'); + $table->morphs('addressable'); $table->string('label')->nullable(); $table->string('name_prefix')->nullable(); $table->string('first_name')->nullable(); From 17b4c082bdf5fe59dbfc9e7dca03eaf8bb9fca4c Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 02:59:30 +0200 Subject: [PATCH 34/65] Update composer package keywords --- composer.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/composer.json b/composer.json index 584c133..a2c0824 100755 --- a/composer.json +++ b/composer.json @@ -2,8 +2,12 @@ "name": "rinvex/addressable", "description": "Rinvex Addressable 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", @@ -11,6 +15,8 @@ "billing", "shipping", "eloquent", + "latitude", + "longitude", "addressable", "polymorphic" ], From 263065321f40dd72e7e2f07cf34a4f0baebb81fd Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 02:59:48 +0200 Subject: [PATCH 35/65] Fix validation rules --- src/Address.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Address.php b/src/Address.php index 82dd5f7..d7e5bc0 100755 --- a/src/Address.php +++ b/src/Address.php @@ -155,8 +155,8 @@ public function __construct(array $attributes = []) $this->setTable(config('rinvex.addressable.tables.addresses')); $this->setRules([ 'addressable_id' => 'required|integer', - 'addressable_type' => 'nullable|string|max:150', - 'label' => 'required|integer|exists:'.config('rinvex.addressable.tables.resources').',id', + 'addressable_type' => 'required|string|max:150', + 'label' => 'nullable|string|max:150', 'name_prefix' => 'nullable|string|max:150', 'first_name' => 'nullable|string|max:150', 'middle_name' => 'nullable|string|max:150', From d1c41ca74a5c93f705a935525e12388161253a12 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 03:00:04 +0200 Subject: [PATCH 36/65] Fix wrong local scope --- src/Address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Address.php b/src/Address.php index d7e5bc0..1561fdc 100755 --- a/src/Address.php +++ b/src/Address.php @@ -217,7 +217,7 @@ public function scopeIsBilling(Builder $builder): Builder * * @return \Illuminate\Database\Eloquent\Builder */ - public function createAddress(Builder $builder): Builder + public function scopeIsShipping(Builder $builder): Builder { return $builder->where('is_shipping', true); } From 47fabf653c27a8f7bcb9fc808d84340a185ffad6 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 03:00:41 +0200 Subject: [PATCH 37/65] Fix country local scope --- src/Address.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Address.php b/src/Address.php index 1561fdc..e3affbc 100755 --- a/src/Address.php +++ b/src/Address.php @@ -226,13 +226,13 @@ public function scopeIsShipping(Builder $builder): Builder * Scope addresses by the given country. * * @param \Illuminate\Database\Eloquent\Builder $builder - * @param string|null $countryCode + * @param string $countryCode * * @return \Illuminate\Database\Eloquent\Builder */ - public function scopeInCountry(Builder $builder, string $countryCode = null): Builder + public function scopeInCountry(Builder $builder, string $countryCode): Builder { - return $countryCode ? $builder->where('country_code', $countryCode) : $builder; + return $builder->where('country_code', $countryCode); } /** From 0433497a54a9d77e9340536b32751b2b62e4cf81 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 03:00:57 +0200 Subject: [PATCH 38/65] Remove useless helper method --- src/Address.php | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Address.php b/src/Address.php index e3affbc..c87faad 100755 --- a/src/Address.php +++ b/src/Address.php @@ -258,14 +258,4 @@ protected static function boot() } }); } - - /** - * Get the address' country. - * - * @return \Rinvex\Country\Country - */ - public function getCountryAttribute() - { - return country($this->country_code); - } } From 179f579dc01e52aa39139dfe1dabbc7f859a3d9b Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 03:01:05 +0200 Subject: [PATCH 39/65] Add language local scope --- src/Address.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Address.php b/src/Address.php index c87faad..d527cf6 100755 --- a/src/Address.php +++ b/src/Address.php @@ -235,6 +235,19 @@ public function scopeInCountry(Builder $builder, string $countryCode): Builder return $builder->where('country_code', $countryCode); } + /** + * Scope addresses by the given language. + * + * @param \Illuminate\Database\Eloquent\Builder $builder + * @param string $languageCode + * + * @return \Illuminate\Database\Eloquent\Builder + */ + public function scopeInLanguage(Builder $builder, string $languageCode): Builder + { + return $builder->where('language_code', $languageCode); + } + /** * {@inheritdoc} */ From 9865e2ca258d88cc8dd13c6d224f97a557d07e07 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 03:01:31 +0200 Subject: [PATCH 40/65] Refactor addressable relashionships --- src/Addressable.php | 76 ++++----------------------------------------- 1 file changed, 6 insertions(+), 70 deletions(-) diff --git a/src/Addressable.php b/src/Addressable.php index 8659287..0be5750 100755 --- a/src/Addressable.php +++ b/src/Addressable.php @@ -33,89 +33,25 @@ abstract public static function deleted($callback); abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null); /** - * Get all attached addresses to the model. - * - * @return \Illuminate\Database\Eloquent\Relations\MorphMany - */ - public function addresses(): MorphMany - { - return $this->morphMany(config('rinvex.addressable.models.address'), 'addressable'); - } - - /** - * Boot the addressable trait for a model. + * Boot the addressable trait for the model. * * @return void */ public static function bootAddressable() { static::deleted(function (Model $addressableModel) { - $addressableModel->addresses()->detach(); + $addressableModel->addresses()->delete(); }); } /** - * Create the given address and attach to the addressable model. - * - * @param array $attributes - * - * @return void - */ - public function addAddress(array $attributes) - { - $addressModel = config('rinvex.addressable.models.address'); - $addressInstance = (new $addressModel())->firstOrCreate($attributes); - $this->addresses()->syncWithoutDetaching($addressInstance); - } - - /** - * Update the given address and attach to the addressable model. - * - * @param \Illuminate\Database\Eloquent\Model $address - * @param array $attributes - * - * @return void - */ - public function updateAddress(Model $address, array $attributes) - { - $address->fill($attributes)->save(); - $this->addresses()->syncWithoutDetaching($address); - } - - /** - * Attach the given address(s) to the addressable model. - * - * @param mixed $addresses - * - * @return void - */ - public function attachAddresses($addresses) - { - $this->addresses()->syncWithoutDetaching($addresses); - } - - /** - * Remove the given address(s) from the addressable model. - * - * @param mixed $addresses - * - * @return void - */ - public function detachAddresses($addresses = null) - { - $this->addresses()->detach($addresses); - } - - /** - * Remove the given address(s) from the addressable model. - * - * @param mixed $addresses + * Get all attached addresses to the model. * - * @return void + * @return \Illuminate\Database\Eloquent\Relations\MorphMany */ - public function removeAddresses($addresses = null) + public function addresses(): MorphMany { - $this->detachAddress($addresses); + return $this->morphMany(config('rinvex.addressable.models.address'), 'addressable'); } /** From 733a4bc1b9cc3a3aac089753b30246f5d725773f Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 19 Jul 2017 03:01:44 +0200 Subject: [PATCH 41/65] Refactor readme and update usage examples --- README.md | 73 +++++++++++++++---------------------------------------- 1 file changed, 19 insertions(+), 54 deletions(-) diff --git a/README.md b/README.md index acf9bfa..627549a 100644 --- a/README.md +++ b/README.md @@ -24,12 +24,7 @@ php artisan migrate --path="vendor/rinvex/addressable/database/migrations" ``` -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 migrations and config files by running the following commands: +3. **Optionally** you can publish migrations and config files by running the following commands: ```shell // Publish migrations php artisan vendor:publish --tag="rinvex-addressable-migrations" @@ -38,14 +33,15 @@ php artisan vendor:publish --tag="rinvex-addressable-config" ``` -5. Done! +4. Done! ## Usage ### Create Your Model -Simply create a new eloquent model, and use `Addressable` trait: +Simply create a new eloquent model, and use `\Rinvex\Addressable\Addressable` trait: + ```php namespace App\Models; @@ -84,25 +80,11 @@ $user->addresses()->create([ 'is_shipping' => true, ]); -// Alternative way of contact create -$user->createAddress([ - 'label' => 'Default Address', - 'name_prefix' => 'Mr.', - 'first_name' => 'Abdelrahman', - 'middle_name' => 'Hossam M. M.', - 'last_name' => 'Omran', - 'name_suffix' => null, - 'organization' => 'Rinvex', - 'country_code' => 'eg', - 'street' => '56 john doe st.', - 'state' => 'Alexandria', - 'city' => 'Alexandria', - 'useral_code' => '21614', - '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 @@ -113,34 +95,17 @@ $address->update([ 'label' => 'Default Work Address', ]); -// Alternative way of address update -$user->updateAddress($address, [ - 'label' => 'Default Work Address', -]); - -// Attach existing address -$user->attachAddresses($address); - -// Attach existing addresses -$user->attachAddresses([1, 2, 3]); - -// Detach existing address -$user->detachAddresses($address); +// Delete address +$address->delete(); -// Detach existing addresses -$user->detachAddresses([1, 2, 3]); - -// Detach all existing addresses -$user->detachAddresses(); - -// 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\Models\User(); @@ -152,19 +117,19 @@ $user->addresses; $user->addresses(); // Scope Primary Addresses -$primaryAddresses = \Rinvex\Addressable\Address::isPrimary(); +$primaryAddresses = \Rinvex\Addressable\Address::isPrimary()->get(); // Scope Billing Addresses -$billingAddresses = \Rinvex\Addressable\Address::isBilling(); +$billingAddresses = \Rinvex\Addressable\Address::isBilling()->get(); // Scope Shipping Addresses -$shippingAddresses = \Rinvex\Addressable\Address::isShipping(); +$shippingAddresses = \Rinvex\Addressable\Address::isShipping()->get(); // Scope Addresses in the given country -$egyptianAddresses = \Rinvex\Addressable\Address::InCountry('eg'); +$egyptianAddresses = \Rinvex\Addressable\Address::InCountry('eg')->get(); // Find all users within 5 kilometers radius from the lat/lng 31.2467601/29.9020376 -$fiveKmAddresses = \App\Models\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 within certain radius $user = new \App\Models\User(); From 0207fbba8a8e1aaa599925ef966e251e56a88415 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 22 Jul 2017 02:05:15 +0200 Subject: [PATCH 42/65] Tweak validation rules --- src/Address.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Address.php b/src/Address.php index d527cf6..dd3ff45 100755 --- a/src/Address.php +++ b/src/Address.php @@ -170,9 +170,9 @@ public function __construct(array $attributes = []) 'postal_code' => 'nullable|string|max:150', 'lat' => 'nullable|numeric', 'lng' => 'nullable|numeric', - 'is_primary' => 'boolean', - 'is_billing' => 'boolean', - 'is_shipping' => 'boolean', + 'is_primary' => 'sometimes|required|boolean', + 'is_billing' => 'sometimes|required|boolean', + 'is_shipping' => 'sometimes|required|boolean', ]); } From d995cb25503f57cd740a16ddfb6b194b829d0626 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 22 Jul 2017 03:24:03 +0200 Subject: [PATCH 43/65] Tweak validation rules --- src/Address.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Address.php b/src/Address.php index dd3ff45..c29160c 100755 --- a/src/Address.php +++ b/src/Address.php @@ -170,9 +170,9 @@ public function __construct(array $attributes = []) 'postal_code' => 'nullable|string|max:150', 'lat' => 'nullable|numeric', 'lng' => 'nullable|numeric', - 'is_primary' => 'sometimes|required|boolean', - 'is_billing' => 'sometimes|required|boolean', - 'is_shipping' => 'sometimes|required|boolean', + 'is_primary' => 'sometimes|boolean', + 'is_billing' => 'sometimes|boolean', + 'is_shipping' => 'sometimes|boolean', ]); } From 098b2a8165e41e997ccd63918cd686a980d5a12e Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 2 Aug 2017 13:00:31 +0200 Subject: [PATCH 44/65] Enforce consistent composer dependencies version range --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index a2c0824..1e26fdd 100755 --- a/composer.json +++ b/composer.json @@ -48,13 +48,13 @@ "require": { "php": "^7.0.0", "jackpopp/geodistance": "^1.2", - "illuminate/support": "~5.5.0", - "illuminate/database": "~5.5.0", + "illuminate/support": "~5.4.0|~5.5.0", + "illuminate/database": "~5.4.0|~5.5.0", "rinvex/cacheable": "dev-develop" }, "require-dev": { "phpunit/phpunit": "^6.0.0", - "illuminate/container": "~5.5.0" + "illuminate/container": "~5.4.0|~5.5.0" }, "autoload": { "classmap": [ From a9450253869c23153b3f5f65426aad6e69c5a7f7 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sun, 13 Aug 2017 03:16:23 +0200 Subject: [PATCH 45/65] Add migration command and simplify installation steps --- README.md | 5 +--- src/AddressableServiceProvider.php | 19 ++++++++++++++ src/Console/Commands/MigrateCommand.php | 35 +++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 src/Console/Commands/MigrateCommand.php diff --git a/README.md b/README.md index 627549a..a1e2315 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,11 @@ 2. Execute migrations via the following command: ``` - php artisan migrate --path="vendor/rinvex/addressable/database/migrations" + php artisan rinvex:migrate:addressable ``` 3. **Optionally** you can publish migrations and config files by running the following commands: ```shell - // Publish migrations - php artisan vendor:publish --tag="rinvex-addressable-migrations" - // Publish config php artisan vendor:publish --tag="rinvex-addressable-config" ``` diff --git a/src/AddressableServiceProvider.php b/src/AddressableServiceProvider.php index 01a63e8..12a3a30 100644 --- a/src/AddressableServiceProvider.php +++ b/src/AddressableServiceProvider.php @@ -5,9 +5,19 @@ namespace Rinvex\Addressable; use Illuminate\Support\ServiceProvider; +use Rinvex\Addressable\Console\Commands\MigrateCommand; class AddressableServiceProvider extends ServiceProvider { + /** + * The commands to be registered. + * + * @var array + */ + protected $commands = [ + MigrateCommand::class => 'command.rinvex.addressable.migrate', + ]; + /** * {@inheritdoc} */ @@ -15,6 +25,15 @@ public function register() { // Merge config $this->mergeConfigFrom(realpath(__DIR__.'/../config/config.php'), 'rinvex.addressable'); + + // Register artisan commands + foreach ($this->commands as $key => $value) { + $this->app->singleton($value, function ($app) use ($key) { + return new $key(); + }); + } + + $this->commands(array_values($this->commands)); } /** diff --git a/src/Console/Commands/MigrateCommand.php b/src/Console/Commands/MigrateCommand.php new file mode 100644 index 0000000..b22cc24 --- /dev/null +++ b/src/Console/Commands/MigrateCommand.php @@ -0,0 +1,35 @@ +warn('Migrate rinvex/addressable:'); + $this->call('migrate', ['--step' => true, '--path' => 'vendor/rinvex/addressable/database/migrations']); + } +} From 810b9a0ef38c07b5d4bfa3eb0e2912a5ae9572ff Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 18 Aug 2017 16:26:36 +0200 Subject: [PATCH 46/65] Enforce consistent namespaces --- README.md | 4 ++-- composer.json | 2 +- src/{ => Models}/Address.php | 0 src/{ => Providers}/AddressableServiceProvider.php | 2 +- src/{ => Traits}/Addressable.php | 2 +- tests/ServiceProviderTest.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) rename src/{ => Models}/Address.php (100%) rename src/{ => Providers}/AddressableServiceProvider.php (97%) rename src/{ => Traits}/Addressable.php (98%) diff --git a/README.md b/README.md index a1e2315..23a9dfb 100644 --- a/README.md +++ b/README.md @@ -37,13 +37,13 @@ ### Create Your Model -Simply create a new eloquent model, and use `\Rinvex\Addressable\Addressable` trait: +Simply create a new eloquent model, and use `\Rinvex\Addressable\Traits\Addressable` trait: ```php namespace App\Models; -use Rinvex\Addressable\Addressable; use Illuminate\Database\Eloquent\Model; +use Rinvex\Addressable\Traits\Addressable; class User extends Model { diff --git a/composer.json b/composer.json index 1e26fdd..e32f9ea 100755 --- a/composer.json +++ b/composer.json @@ -80,7 +80,7 @@ }, "laravel": { "providers": [ - "Rinvex\\Addressable\\AddressableServiceProvider" + "Rinvex\\Addressable\\Providers\\AddressableServiceProvider" ] } }, diff --git a/src/Address.php b/src/Models/Address.php similarity index 100% rename from src/Address.php rename to src/Models/Address.php diff --git a/src/AddressableServiceProvider.php b/src/Providers/AddressableServiceProvider.php similarity index 97% rename from src/AddressableServiceProvider.php rename to src/Providers/AddressableServiceProvider.php index 12a3a30..ea22b71 100644 --- a/src/AddressableServiceProvider.php +++ b/src/Providers/AddressableServiceProvider.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rinvex\Addressable; +namespace Rinvex\Addressable\Providers; use Illuminate\Support\ServiceProvider; use Rinvex\Addressable\Console\Commands\MigrateCommand; diff --git a/src/Addressable.php b/src/Traits/Addressable.php similarity index 98% rename from src/Addressable.php rename to src/Traits/Addressable.php index 0be5750..4cb1f19 100755 --- a/src/Addressable.php +++ b/src/Traits/Addressable.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rinvex\Addressable; +namespace Rinvex\Addressable\Traits; use Illuminate\Support\Collection; use Illuminate\Database\Eloquent\Model; diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 1ec654a..4d97db1 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -8,7 +8,7 @@ use PHPUnit\Framework\TestCase; use Illuminate\Container\Container; use Illuminate\Support\ServiceProvider; -use Rinvex\Addressable\AddressableServiceProvider; +use Rinvex\Addressable\Providers\AddressableServiceProvider; class ServiceProviderTest extends TestCase { From 6cd8ce3903ad2deb66cf123a8c57d03f27c69c28 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 18 Aug 2017 16:43:21 +0200 Subject: [PATCH 47/65] Enforce consistency --- config/config.php | 4 +--- src/Models/Address.php | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/config/config.php b/config/config.php index c6b4abc..efb7d35 100644 --- a/config/config.php +++ b/config/config.php @@ -2,8 +2,6 @@ declare(strict_types=1); -use Rinvex\Addressable\Address; - return [ // Addressable Database Tables @@ -13,7 +11,7 @@ // Addressable Models 'models' => [ - 'address' => Address::class, + 'address' => \Rinvex\Addressable\Models\Address::class, ], // Addressable Geocoding Options diff --git a/src/Models/Address.php b/src/Models/Address.php index c29160c..5ef56da 100755 --- a/src/Models/Address.php +++ b/src/Models/Address.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rinvex\Addressable; +namespace Rinvex\Addressable\Models; use Watson\Validating\ValidatingTrait; use Illuminate\Database\Eloquent\Model; From e8ab52479ff33dd047f514591c23afae6252439b Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 18 Aug 2017 18:27:11 +0200 Subject: [PATCH 48/65] Fix wrong namespace --- README.md | 10 ++++----- src/Models/Address.php | 48 +++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 23a9dfb..63d2be7 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ $user->addresses()->createMany([ ]); // Find an existing address -$address = \Rinvex\Addressable\Address::find(1); +$address = \Rinvex\Addressable\Models\Address::find(1); // Update an existing address $address->update([ @@ -114,16 +114,16 @@ $user->addresses; $user->addresses(); // Scope Primary Addresses -$primaryAddresses = \Rinvex\Addressable\Address::isPrimary()->get(); +$primaryAddresses = \Rinvex\Addressable\Models\Address::isPrimary()->get(); // Scope Billing Addresses -$billingAddresses = \Rinvex\Addressable\Address::isBilling()->get(); +$billingAddresses = \Rinvex\Addressable\Models\Address::isBilling()->get(); // Scope Shipping Addresses -$shippingAddresses = \Rinvex\Addressable\Address::isShipping()->get(); +$shippingAddresses = \Rinvex\Addressable\Models\Address::isShipping()->get(); // Scope Addresses in the given country -$egyptianAddresses = \Rinvex\Addressable\Address::InCountry('eg')->get(); +$egyptianAddresses = \Rinvex\Addressable\Models\Address::InCountry('eg')->get(); // Find all users within 5 kilometers radius from the lat/lng 31.2467601/29.9020376 $fiveKmAddresses = \App\Models\User::findByDistance(5, 'kilometers', '31.2467601', '29.9020376')->get(); diff --git a/src/Models/Address.php b/src/Models/Address.php index 5ef56da..865fd77 100755 --- a/src/Models/Address.php +++ b/src/Models/Address.php @@ -37,30 +37,30 @@ * @property string $deleted_at * @property-read \Rinvex\Country\Country $country * - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address inCountry($countryCode = null) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address isBilling() - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address isPrimary() - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereCity($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereCountryCode($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereDeletedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereFirstName($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereIsBilling($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereIsPrimary($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereIsShipping($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereLabel($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereLastName($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereLat($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereLng($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereMiddleName($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereNamePrefix($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereNameSuffix($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereOrganization($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address wherePostalCode($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereState($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereStreet($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Address whereUpdatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address inCountry($countryCode = null) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address isBilling() + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address isPrimary() + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereCity($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereCountryCode($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereCreatedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereDeletedAt($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereFirstName($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereId($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereIsBilling($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereIsPrimary($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereIsShipping($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereLabel($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereLastName($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereLat($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereLng($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereMiddleName($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereNamePrefix($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereNameSuffix($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereOrganization($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address wherePostalCode($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereState($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereStreet($value) + * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereUpdatedAt($value) * @mixin \Eloquent */ class Address extends Model From cec210ae20519bdb6dfc2969fc7e4936b17ad8b5 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 18 Aug 2017 18:41:42 +0200 Subject: [PATCH 49/65] Fix wrong config path --- src/Providers/AddressableServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Providers/AddressableServiceProvider.php b/src/Providers/AddressableServiceProvider.php index ea22b71..2cb2e7f 100644 --- a/src/Providers/AddressableServiceProvider.php +++ b/src/Providers/AddressableServiceProvider.php @@ -24,7 +24,7 @@ class AddressableServiceProvider extends ServiceProvider public function register() { // Merge config - $this->mergeConfigFrom(realpath(__DIR__.'/../config/config.php'), 'rinvex.addressable'); + $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.addressable'); // Register artisan commands foreach ($this->commands as $key => $value) { From 433c7b959f332af364ce94f1641096bf1de7f3b2 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 18 Aug 2017 18:46:59 +0200 Subject: [PATCH 50/65] Fix migration path --- src/Providers/AddressableServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Providers/AddressableServiceProvider.php b/src/Providers/AddressableServiceProvider.php index 2cb2e7f..c07e37f 100644 --- a/src/Providers/AddressableServiceProvider.php +++ b/src/Providers/AddressableServiceProvider.php @@ -43,7 +43,7 @@ public function boot() { if ($this->app->runningInConsole()) { // Load migrations - $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); + $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); // Publish Resources $this->publishResources(); From 85072c7d10afc6f03a072c32fe040632a4848d53 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 19 Aug 2017 05:19:22 +0200 Subject: [PATCH 51/65] Fix config & migration paths --- src/Providers/AddressableServiceProvider.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Providers/AddressableServiceProvider.php b/src/Providers/AddressableServiceProvider.php index c07e37f..92c6c5f 100644 --- a/src/Providers/AddressableServiceProvider.php +++ b/src/Providers/AddressableServiceProvider.php @@ -26,6 +26,11 @@ public function register() // Merge config $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.addressable'); + // Register eloquent models + $this->app->singleton('rinvex.addressable', function ($app) { + return new $app['config']['rinvex.addressable.models.address']; + }); + // Register artisan commands foreach ($this->commands as $key => $value) { $this->app->singleton($value, function ($app) use ($key) { @@ -57,7 +62,7 @@ public function boot() */ protected function publishResources() { - $this->publishes([realpath(__DIR__.'/../config/config.php') => config_path('rinvex.addressable.php')], 'rinvex-addressable-config'); - $this->publishes([realpath(__DIR__.'/../database/migrations') => database_path('migrations')], 'rinvex-addressable-migrations'); + $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.addressable.php')], 'rinvex-addressable-config'); + $this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'rinvex-addressable-migrations'); } } From 25d7588015f3f6a6063bceaa1185c7cd36fc2371 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 19 Aug 2017 05:32:18 +0200 Subject: [PATCH 52/65] Use IoC bound model instead of the explicitly hardcoded --- README.md | 10 +++++----- src/Providers/AddressableServiceProvider.php | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 63d2be7..40f3623 100644 --- a/README.md +++ b/README.md @@ -85,7 +85,7 @@ $user->addresses()->createMany([ ]); // Find an existing address -$address = \Rinvex\Addressable\Models\Address::find(1); +$address = app('rinvex.addressable.address')->find(1); // Update an existing address $address->update([ @@ -114,16 +114,16 @@ $user->addresses; $user->addresses(); // Scope Primary Addresses -$primaryAddresses = \Rinvex\Addressable\Models\Address::isPrimary()->get(); +$primaryAddresses = app('rinvex.addressable.address')->isPrimary()->get(); // Scope Billing Addresses -$billingAddresses = \Rinvex\Addressable\Models\Address::isBilling()->get(); +$billingAddresses = app('rinvex.addressable.address')->isBilling()->get(); // Scope Shipping Addresses -$shippingAddresses = \Rinvex\Addressable\Models\Address::isShipping()->get(); +$shippingAddresses = app('rinvex.addressable.address')->isShipping()->get(); // Scope Addresses in the given country -$egyptianAddresses = \Rinvex\Addressable\Models\Address::InCountry('eg')->get(); +$egyptianAddresses = app('rinvex.addressable.address')->InCountry('eg')->get(); // Find all users within 5 kilometers radius from the lat/lng 31.2467601/29.9020376 $fiveKmAddresses = \App\Models\User::findByDistance(5, 'kilometers', '31.2467601', '29.9020376')->get(); diff --git a/src/Providers/AddressableServiceProvider.php b/src/Providers/AddressableServiceProvider.php index 92c6c5f..c5f5e7c 100644 --- a/src/Providers/AddressableServiceProvider.php +++ b/src/Providers/AddressableServiceProvider.php @@ -27,7 +27,7 @@ public function register() $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.addressable'); // Register eloquent models - $this->app->singleton('rinvex.addressable', function ($app) { + $this->app->singleton('rinvex.addressable.address', function ($app) { return new $app['config']['rinvex.addressable.models.address']; }); From f8fb86619b44bcaea716811f271b4cc37e9b1a83 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sat, 19 Aug 2017 03:37:24 +0000 Subject: [PATCH 53/65] Apply fixes from StyleCI --- src/Providers/AddressableServiceProvider.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Providers/AddressableServiceProvider.php b/src/Providers/AddressableServiceProvider.php index c5f5e7c..2d35195 100644 --- a/src/Providers/AddressableServiceProvider.php +++ b/src/Providers/AddressableServiceProvider.php @@ -28,7 +28,7 @@ public function register() // Register eloquent models $this->app->singleton('rinvex.addressable.address', function ($app) { - return new $app['config']['rinvex.addressable.models.address']; + return new $app['config']['rinvex.addressable.models.address'](); }); // Register artisan commands From 7d942ebd61308e42e05726f4cfa5899929c0b6e3 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Sun, 20 Aug 2017 14:11:17 +0200 Subject: [PATCH 54/65] Bind model alias into IoC container --- src/Providers/AddressableServiceProvider.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Providers/AddressableServiceProvider.php b/src/Providers/AddressableServiceProvider.php index 2d35195..98fc80b 100644 --- a/src/Providers/AddressableServiceProvider.php +++ b/src/Providers/AddressableServiceProvider.php @@ -4,6 +4,7 @@ namespace Rinvex\Addressable\Providers; +use Rinvex\Addressable\Models\Address; use Illuminate\Support\ServiceProvider; use Rinvex\Addressable\Console\Commands\MigrateCommand; @@ -26,10 +27,11 @@ public function register() // Merge config $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.addressable'); - // Register eloquent models + // Bind eloquent models to IoC container $this->app->singleton('rinvex.addressable.address', function ($app) { return new $app['config']['rinvex.addressable.models.address'](); }); + $this->app->alias('rinvex.addressable.address', Address::class); // Register artisan commands foreach ($this->commands as $key => $value) { From 1d0e9722cb977003dc208c9f0d94abd3c4f7354e Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 22 Aug 2017 00:29:37 +0200 Subject: [PATCH 55/65] Tweak service provider and enforce consistency --- src/Providers/AddressableServiceProvider.php | 37 ++++++++++++-------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/Providers/AddressableServiceProvider.php b/src/Providers/AddressableServiceProvider.php index 98fc80b..172e396 100644 --- a/src/Providers/AddressableServiceProvider.php +++ b/src/Providers/AddressableServiceProvider.php @@ -33,14 +33,8 @@ public function register() }); $this->app->alias('rinvex.addressable.address', Address::class); - // Register artisan commands - foreach ($this->commands as $key => $value) { - $this->app->singleton($value, function ($app) use ($key) { - return new $key(); - }); - } - - $this->commands(array_values($this->commands)); + // Register console commands + ! $this->app->runningInConsole() || $this->registerCommands(); } /** @@ -48,13 +42,11 @@ public function register() */ public function boot() { - if ($this->app->runningInConsole()) { - // Load migrations - $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); + // Load migrations + ! $this->app->runningInConsole() || $this->loadMigrationsFrom(__DIR__.'/../../database/migrations'); - // Publish Resources - $this->publishResources(); - } + // Publish Resources + ! $this->app->runningInConsole() || $this->publishResources(); } /** @@ -67,4 +59,21 @@ protected function publishResources() $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.addressable.php')], 'rinvex-addressable-config'); $this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'rinvex-addressable-migrations'); } + + /** + * Register console commands. + * + * @return void + */ + protected function registerCommands() + { + // Register artisan commands + foreach ($this->commands as $key => $value) { + $this->app->singleton($value, function ($app) use ($key) { + return new $key(); + }); + } + + $this->commands(array_values($this->commands)); + } } From b12f24e795fe79c714e0808da3104b570145396d Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Tue, 22 Aug 2017 19:23:06 +0200 Subject: [PATCH 56/65] Update models docblock --- src/Models/Address.php | 100 ++++++++++++++++++++++------------------- 1 file changed, 53 insertions(+), 47 deletions(-) diff --git a/src/Models/Address.php b/src/Models/Address.php index 865fd77..8178a44 100755 --- a/src/Models/Address.php +++ b/src/Models/Address.php @@ -12,55 +12,61 @@ use Illuminate\Database\Eloquent\Relations\MorphTo; /** - * Rinvex\Addressable\Address. + * Rinvex\Addressable\Models\Address. * - * @property int $id - * @property string $label - * @property string $name_prefix - * @property string $first_name - * @property string $middle_name - * @property string $last_name - * @property string $name_suffix - * @property string $organization - * @property string $country_code - * @property string $street - * @property string $state - * @property string $city - * @property string $postal_code - * @property float $lat - * @property float $lng - * @property bool $is_primary - * @property bool $is_billing - * @property bool $is_shipping - * @property \Carbon\Carbon $created_at - * @property \Carbon\Carbon $updated_at - * @property string $deleted_at - * @property-read \Rinvex\Country\Country $country + * @property int $id + * @property int $addressable_id + * @property string $addressable_type + * @property string $label + * @property string $name_prefix + * @property string $first_name + * @property string $middle_name + * @property string $last_name + * @property string $name_suffix + * @property string $organization + * @property string $country_code + * @property string $street + * @property string $state + * @property string $city + * @property string $postal_code + * @property float $lat + * @property float $lng + * @property bool $is_primary + * @property bool $is_billing + * @property bool $is_shipping + * @property \Carbon\Carbon $created_at + * @property \Carbon\Carbon $updated_at + * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $addressable * - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address inCountry($countryCode = null) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address isBilling() - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address isPrimary() - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereCity($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereCountryCode($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereCreatedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereDeletedAt($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereFirstName($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereId($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereIsBilling($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereIsPrimary($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereIsShipping($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereLabel($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereLastName($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereLat($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereLng($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereMiddleName($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereNamePrefix($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereNameSuffix($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereOrganization($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address wherePostalCode($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereState($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereStreet($value) - * @method static \Illuminate\Database\Query\Builder|\Rinvex\Addressable\Models\Address whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address inCountry($countryCode) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address inLanguage($languageCode) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address isBilling() + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address isPrimary() + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address isShipping() + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address outside($distance, $measurement = null, $lat = null, $lng = null) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereAddressableId($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereAddressableType($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereCity($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereCountryCode($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereFirstName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereIsBilling($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereIsPrimary($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereIsShipping($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLabel($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLastName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLat($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLng($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereMiddleName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereNamePrefix($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereNameSuffix($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereOrganization($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address wherePostalCode($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereState($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereStreet($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address within($distance, $measurement = null, $lat = null, $lng = null) * @mixin \Eloquent */ class Address extends Model From 2bbbe76928e9ad10c6b660341308ce80555fe122 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Wed, 23 Aug 2017 04:45:37 +0200 Subject: [PATCH 57/65] Program to an interface not implementation for flexible model swapping --- src/Contracts/AddressContract.php | 68 ++++++++++++++++++++ src/Models/Address.php | 3 +- src/Providers/AddressableServiceProvider.php | 4 +- 3 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/Contracts/AddressContract.php diff --git a/src/Contracts/AddressContract.php b/src/Contracts/AddressContract.php new file mode 100644 index 0000000..a833a7d --- /dev/null +++ b/src/Contracts/AddressContract.php @@ -0,0 +1,68 @@ +app->singleton('rinvex.addressable.address', function ($app) { return new $app['config']['rinvex.addressable.models.address'](); }); - $this->app->alias('rinvex.addressable.address', Address::class); + $this->app->alias('rinvex.addressable.address', AddressContract::class); // Register console commands ! $this->app->runningInConsole() || $this->registerCommands(); From d20b71d40a4261a3c168e65bb0b584b802467bf0 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 24 Aug 2017 21:22:05 +0200 Subject: [PATCH 58/65] Override ValidatingTrait --- src/Models/Address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Address.php b/src/Models/Address.php index f9cc7d7..47172b9 100755 --- a/src/Models/Address.php +++ b/src/Models/Address.php @@ -4,10 +4,10 @@ namespace Rinvex\Addressable\Models; -use Watson\Validating\ValidatingTrait; use Illuminate\Database\Eloquent\Model; use Rinvex\Cacheable\CacheableEloquent; use Illuminate\Database\Eloquent\Builder; +use Rinvex\Support\Traits\ValidatingTrait; use Jackpopp\GeoDistance\GeoDistanceTrait; use Rinvex\Addressable\Contracts\AddressContract; use Illuminate\Database\Eloquent\Relations\MorphTo; From a44f8bc6ab0b980de2f4f5224664322a246613a8 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 24 Aug 2017 19:22:45 +0000 Subject: [PATCH 59/65] Apply fixes from StyleCI --- src/Models/Address.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Models/Address.php b/src/Models/Address.php index 47172b9..c5b4590 100755 --- a/src/Models/Address.php +++ b/src/Models/Address.php @@ -7,8 +7,8 @@ use Illuminate\Database\Eloquent\Model; use Rinvex\Cacheable\CacheableEloquent; use Illuminate\Database\Eloquent\Builder; -use Rinvex\Support\Traits\ValidatingTrait; use Jackpopp\GeoDistance\GeoDistanceTrait; +use Rinvex\Support\Traits\ValidatingTrait; use Rinvex\Addressable\Contracts\AddressContract; use Illuminate\Database\Eloquent\Relations\MorphTo; From f0eb994b28f4d2776f696cb2b3f4fa1cf6a3d363 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 31 Aug 2017 00:07:17 +0200 Subject: [PATCH 60/65] Simplify installation steps by removing optional low-priority steps --- README.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/README.md b/README.md index 40f3623..90a2552 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,7 @@ php artisan rinvex:migrate:addressable ``` -3. **Optionally** you can publish migrations and config files by running the following commands: - ```shell - // Publish config - php artisan vendor:publish --tag="rinvex-addressable-config" - ``` - -4. Done! +3. Done! ## Usage From f7fdf31a0d8241711ee106cfb9095de18deca0a7 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 31 Aug 2017 00:07:23 +0200 Subject: [PATCH 61/65] Enforce consistency --- src/Traits/Addressable.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Traits/Addressable.php b/src/Traits/Addressable.php index 4cb1f19..af460a9 100755 --- a/src/Traits/Addressable.php +++ b/src/Traits/Addressable.php @@ -39,8 +39,8 @@ abstract public function morphMany($related, $name, $type = null, $id = null, $l */ public static function bootAddressable() { - static::deleted(function (Model $addressableModel) { - $addressableModel->addresses()->delete(); + static::deleted(function (self $model) { + $model->addresses()->delete(); }); } From 7c6fcc974fb4d9b4b58c454d7aacfdc5789b11aa Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 31 Aug 2017 20:24:52 +0200 Subject: [PATCH 62/65] Disable travis email notifications --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 5786500..f81c04d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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= From 55498c298ab68bdc6eb093a7ae39995f60eb2fa9 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Thu, 31 Aug 2017 20:54:12 +0200 Subject: [PATCH 63/65] Update composer dependencies --- composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index e32f9ea..2d30a9a 100755 --- a/composer.json +++ b/composer.json @@ -48,13 +48,13 @@ "require": { "php": "^7.0.0", "jackpopp/geodistance": "^1.2", - "illuminate/support": "~5.4.0|~5.5.0", - "illuminate/database": "~5.4.0|~5.5.0", + "illuminate/support": "~5.5.0", + "illuminate/database": "~5.5.0", "rinvex/cacheable": "dev-develop" }, "require-dev": { "phpunit/phpunit": "^6.0.0", - "illuminate/container": "~5.4.0|~5.5.0" + "illuminate/container": "~5.5.0" }, "autoload": { "classmap": [ From 0a9eda32272721002837fdcbbbb678a967723c4f Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 8 Sep 2017 21:37:10 +0200 Subject: [PATCH 64/65] Rename package rinvex/addresses from rinvex/addressable --- CHANGELOG.md | 2 +- README.md | 34 +++++----- composer.json | 18 ++--- config/config.php | 8 +-- ...17_03_31_005125_create_addresses_table.php | 4 +- phpunit.xml.dist | 2 +- src/Console/Commands/MigrateCommand.php | 10 +-- src/Contracts/AddressContract.php | 62 ++++++++--------- src/Models/Address.php | 68 +++++++++---------- ...vider.php => AddressesServiceProvider.php} | 22 +++--- src/Traits/Addressable.php | 6 +- tests/ServiceProviderTest.php | 6 +- 12 files changed, 121 insertions(+), 121 deletions(-) rename src/Providers/{AddressableServiceProvider.php => AddressesServiceProvider.php} (68%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e54923c..06718f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -# Rinvex Addressable Change Log +# Rinvex Addresses Change Log All notable changes to this project will be documented in this file. diff --git a/README.md b/README.md index 90a2552..db0e9f1 100644 --- a/README.md +++ b/README.md @@ -1,27 +1,27 @@ -# 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 rinvex:migrate:addressable + php artisan rinvex:migrate:addresses ``` 3. Done! @@ -31,13 +31,13 @@ ### Create Your Model -Simply create a new eloquent model, and use `\Rinvex\Addressable\Traits\Addressable` trait: +Simply create a new eloquent model, and use `\Rinvex\Addresses\Traits\Addressable` trait: ```php namespace App\Models; use Illuminate\Database\Eloquent\Model; -use Rinvex\Addressable\Traits\Addressable; +use Rinvex\Addresses\Traits\Addressable; class User extends Model { @@ -79,7 +79,7 @@ $user->addresses()->createMany([ ]); // Find an existing address -$address = app('rinvex.addressable.address')->find(1); +$address = app('rinvex.addresses.address')->find(1); // Update an existing address $address->update([ @@ -108,16 +108,16 @@ $user->addresses; $user->addresses(); // Scope Primary Addresses -$primaryAddresses = app('rinvex.addressable.address')->isPrimary()->get(); +$primaryAddresses = app('rinvex.addresses.address')->isPrimary()->get(); // Scope Billing Addresses -$billingAddresses = app('rinvex.addressable.address')->isBilling()->get(); +$billingAddresses = app('rinvex.addresses.address')->isBilling()->get(); // Scope Shipping Addresses -$shippingAddresses = app('rinvex.addressable.address')->isShipping()->get(); +$shippingAddresses = app('rinvex.addresses.address')->isShipping()->get(); // Scope Addresses in the given country -$egyptianAddresses = app('rinvex.addressable.address')->InCountry('eg')->get(); +$egyptianAddresses = app('rinvex.addresses.address')->InCountry('eg')->get(); // Find all users within 5 kilometers radius from the lat/lng 31.2467601/29.9020376 $fiveKmAddresses = \App\Models\User::findByDistance(5, 'kilometers', '31.2467601', '29.9020376')->get(); diff --git a/composer.json b/composer.json index 2d30a9a..74c7c14 100755 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { - "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", @@ -24,9 +24,9 @@ "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": [ { @@ -42,7 +42,7 @@ }, { "name": "The Generous Laravel Community", - "homepage": "https://github.com/rinvex/addressable/contributors" + "homepage": "https://github.com/rinvex/addresses/contributors" } ], "require": { @@ -61,12 +61,12 @@ "database" ], "psr-4": { - "Rinvex\\Addressable\\": "src/" + "Rinvex\\Addresses\\": "src/" } }, "autoload-dev": { "psr-4": { - "Rinvex\\Addressable\\Test\\": "tests" + "Rinvex\\Addresses\\Test\\": "tests" } }, "config": { @@ -80,7 +80,7 @@ }, "laravel": { "providers": [ - "Rinvex\\Addressable\\Providers\\AddressableServiceProvider" + "Rinvex\\Addresses\\Providers\\AddressesServiceProvider" ] } }, diff --git a/config/config.php b/config/config.php index efb7d35..62b9a77 100644 --- a/config/config.php +++ b/config/config.php @@ -4,17 +4,17 @@ return [ - // Addressable Database Tables + // Addresses Database Tables 'tables' => [ 'addresses' => 'addresses', ], - // Addressable Models + // Addresses Models 'models' => [ - 'address' => \Rinvex\Addressable\Models\Address::class, + 'address' => \Rinvex\Addresses\Models\Address::class, ], - // Addressable Geocoding Options + // Addresses Geocoding Options 'geocoding' => false, ]; diff --git a/database/migrations/2017_03_31_005125_create_addresses_table.php b/database/migrations/2017_03_31_005125_create_addresses_table.php index 7fc6b94..539adb7 100755 --- a/database/migrations/2017_03_31_005125_create_addresses_table.php +++ b/database/migrations/2017_03_31_005125_create_addresses_table.php @@ -9,7 +9,7 @@ class CreateAddressesTable extends Migration { public function up() { - Schema::create(config('rinvex.addressable.tables.addresses'), function (Blueprint $table) { + Schema::create(config('rinvex.addresses.tables.addresses'), function (Blueprint $table) { // Columns $table->increments('id'); $table->morphs('addressable'); @@ -36,6 +36,6 @@ public function up() public function down() { - Schema::dropIfExists(config('rinvex.addressable.tables.addresses')); + Schema::dropIfExists(config('rinvex.addresses.tables.addresses')); } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 221c1e2..4764548 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,7 +13,7 @@ beStrictAboutChangesToGlobalState="true" beStrictAboutCoversAnnotation="true"> - + tests diff --git a/src/Console/Commands/MigrateCommand.php b/src/Console/Commands/MigrateCommand.php index b22cc24..d046881 100644 --- a/src/Console/Commands/MigrateCommand.php +++ b/src/Console/Commands/MigrateCommand.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rinvex\Addressable\Console\Commands; +namespace Rinvex\Addresses\Console\Commands; use Illuminate\Console\Command; @@ -13,14 +13,14 @@ class MigrateCommand extends Command * * @var string */ - protected $signature = 'rinvex:migrate:addressable'; + protected $signature = 'rinvex:migrate:addresses'; /** * The console command description. * * @var string */ - protected $description = 'Migrate Rinvex Addressable Tables.'; + protected $description = 'Migrate Rinvex Addresses Tables.'; /** * Execute the console command. @@ -29,7 +29,7 @@ class MigrateCommand extends Command */ public function handle() { - $this->warn('Migrate rinvex/addressable:'); - $this->call('migrate', ['--step' => true, '--path' => 'vendor/rinvex/addressable/database/migrations']); + $this->warn('Migrate rinvex/addresses:'); + $this->call('migrate', ['--step' => true, '--path' => 'vendor/rinvex/addresses/database/migrations']); } } diff --git a/src/Contracts/AddressContract.php b/src/Contracts/AddressContract.php index a833a7d..9a9820f 100644 --- a/src/Contracts/AddressContract.php +++ b/src/Contracts/AddressContract.php @@ -2,10 +2,10 @@ declare(strict_types=1); -namespace Rinvex\Addressable\Contracts; +namespace Rinvex\Addresses\Contracts; /** - * Rinvex\Addressable\Contracts\AddressContract. + * Rinvex\Addresses\Contracts\AddressContract. * * @property int $id * @property int $addressable_id @@ -31,35 +31,35 @@ * @property \Carbon\Carbon $updated_at * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $addressable * - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address inCountry($countryCode) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address inLanguage($languageCode) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address isBilling() - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address isPrimary() - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address isShipping() - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address outside($distance, $measurement = null, $lat = null, $lng = null) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereAddressableId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereAddressableType($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereCity($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereCountryCode($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereCreatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereFirstName($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereIsBilling($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereIsPrimary($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereIsShipping($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLabel($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLastName($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLat($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLng($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereMiddleName($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereNamePrefix($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereNameSuffix($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereOrganization($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address wherePostalCode($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereState($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereStreet($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereUpdatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address within($distance, $measurement = null, $lat = null, $lng = null) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address inCountry($countryCode) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address inLanguage($languageCode) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address isBilling() + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address isPrimary() + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address isShipping() + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address outside($distance, $measurement = null, $lat = null, $lng = null) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereAddressableId($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereAddressableType($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereCity($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereCountryCode($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereFirstName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereIsBilling($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereIsPrimary($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereIsShipping($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereLabel($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereLastName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereLat($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereLng($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereMiddleName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereNamePrefix($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereNameSuffix($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereOrganization($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address wherePostalCode($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereState($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereStreet($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address within($distance, $measurement = null, $lat = null, $lng = null) * @mixin \Eloquent */ interface AddressContract diff --git a/src/Models/Address.php b/src/Models/Address.php index c5b4590..89508be 100755 --- a/src/Models/Address.php +++ b/src/Models/Address.php @@ -2,18 +2,18 @@ declare(strict_types=1); -namespace Rinvex\Addressable\Models; +namespace Rinvex\Addresses\Models; use Illuminate\Database\Eloquent\Model; use Rinvex\Cacheable\CacheableEloquent; use Illuminate\Database\Eloquent\Builder; use Jackpopp\GeoDistance\GeoDistanceTrait; use Rinvex\Support\Traits\ValidatingTrait; -use Rinvex\Addressable\Contracts\AddressContract; +use Rinvex\Addresses\Contracts\AddressContract; use Illuminate\Database\Eloquent\Relations\MorphTo; /** - * Rinvex\Addressable\Models\Address. + * Rinvex\Addresses\Models\Address. * * @property int $id * @property int $addressable_id @@ -39,35 +39,35 @@ * @property \Carbon\Carbon $updated_at * @property-read \Illuminate\Database\Eloquent\Model|\Eloquent $addressable * - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address inCountry($countryCode) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address inLanguage($languageCode) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address isBilling() - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address isPrimary() - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address isShipping() - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address outside($distance, $measurement = null, $lat = null, $lng = null) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereAddressableId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereAddressableType($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereCity($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereCountryCode($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereCreatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereFirstName($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereId($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereIsBilling($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereIsPrimary($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereIsShipping($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLabel($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLastName($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLat($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereLng($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereMiddleName($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereNamePrefix($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereNameSuffix($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereOrganization($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address wherePostalCode($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereState($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereStreet($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address whereUpdatedAt($value) - * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addressable\Models\Address within($distance, $measurement = null, $lat = null, $lng = null) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address inCountry($countryCode) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address inLanguage($languageCode) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address isBilling() + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address isPrimary() + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address isShipping() + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address outside($distance, $measurement = null, $lat = null, $lng = null) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereAddressableId($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereAddressableType($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereCity($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereCountryCode($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereCreatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereFirstName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereId($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereIsBilling($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereIsPrimary($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereIsShipping($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereLabel($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereLastName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereLat($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereLng($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereMiddleName($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereNamePrefix($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereNameSuffix($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereOrganization($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address wherePostalCode($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereState($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereStreet($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address whereUpdatedAt($value) + * @method static \Illuminate\Database\Eloquent\Builder|\Rinvex\Addresses\Models\Address within($distance, $measurement = null, $lat = null, $lng = null) * @mixin \Eloquent */ class Address extends Model implements AddressContract @@ -159,7 +159,7 @@ public function __construct(array $attributes = []) { parent::__construct($attributes); - $this->setTable(config('rinvex.addressable.tables.addresses')); + $this->setTable(config('rinvex.addresses.tables.addresses')); $this->setRules([ 'addressable_id' => 'required|integer', 'addressable_type' => 'required|string|max:150', @@ -263,7 +263,7 @@ protected static function boot() parent::boot(); static::saving(function (self $address) { - if (config('rinvex.addressable.geocoding')) { + if (config('rinvex.addresses.geocoding')) { $segments[] = $address->street; $segments[] = sprintf('%s, %s %s', $address->city, $address->state, $address->postal_code); $segments[] = country($address->country_code)->getName(); diff --git a/src/Providers/AddressableServiceProvider.php b/src/Providers/AddressesServiceProvider.php similarity index 68% rename from src/Providers/AddressableServiceProvider.php rename to src/Providers/AddressesServiceProvider.php index c88bb53..d18a600 100644 --- a/src/Providers/AddressableServiceProvider.php +++ b/src/Providers/AddressesServiceProvider.php @@ -2,13 +2,13 @@ declare(strict_types=1); -namespace Rinvex\Addressable\Providers; +namespace Rinvex\Addresses\Providers; use Illuminate\Support\ServiceProvider; -use Rinvex\Addressable\Contracts\AddressContract; -use Rinvex\Addressable\Console\Commands\MigrateCommand; +use Rinvex\Addresses\Contracts\AddressContract; +use Rinvex\Addresses\Console\Commands\MigrateCommand; -class AddressableServiceProvider extends ServiceProvider +class AddressesServiceProvider extends ServiceProvider { /** * The commands to be registered. @@ -16,7 +16,7 @@ class AddressableServiceProvider extends ServiceProvider * @var array */ protected $commands = [ - MigrateCommand::class => 'command.rinvex.addressable.migrate', + MigrateCommand::class => 'command.rinvex.addresses.migrate', ]; /** @@ -25,13 +25,13 @@ class AddressableServiceProvider extends ServiceProvider public function register() { // Merge config - $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.addressable'); + $this->mergeConfigFrom(realpath(__DIR__.'/../../config/config.php'), 'rinvex.addresses'); // Bind eloquent models to IoC container - $this->app->singleton('rinvex.addressable.address', function ($app) { - return new $app['config']['rinvex.addressable.models.address'](); + $this->app->singleton('rinvex.addresses.address', function ($app) { + return new $app['config']['rinvex.addresses.models.address'](); }); - $this->app->alias('rinvex.addressable.address', AddressContract::class); + $this->app->alias('rinvex.addresses.address', AddressContract::class); // Register console commands ! $this->app->runningInConsole() || $this->registerCommands(); @@ -56,8 +56,8 @@ public function boot() */ protected function publishResources() { - $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.addressable.php')], 'rinvex-addressable-config'); - $this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'rinvex-addressable-migrations'); + $this->publishes([realpath(__DIR__.'/../../config/config.php') => config_path('rinvex.addresses.php')], 'rinvex-addresses-config'); + $this->publishes([realpath(__DIR__.'/../../database/migrations') => database_path('migrations')], 'rinvex-addresses-migrations'); } /** diff --git a/src/Traits/Addressable.php b/src/Traits/Addressable.php index af460a9..749e5eb 100755 --- a/src/Traits/Addressable.php +++ b/src/Traits/Addressable.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Rinvex\Addressable\Traits; +namespace Rinvex\Addresses\Traits; use Illuminate\Support\Collection; use Illuminate\Database\Eloquent\Model; @@ -51,7 +51,7 @@ public static function bootAddressable() */ public function addresses(): MorphMany { - return $this->morphMany(config('rinvex.addressable.models.address'), 'addressable'); + return $this->morphMany(config('rinvex.addresses.models.address'), 'addressable'); } /** @@ -66,7 +66,7 @@ public function addresses(): MorphMany */ public static function findByDistance($distance, $unit, $lat, $lng): Collection { - $addressModel = config('rinvex.addressable.models.address'); + $addressModel = config('rinvex.addresses.models.address'); $records = (new $addressModel())->within($distance, $unit, $lat, $lng)->get(); $results = []; diff --git a/tests/ServiceProviderTest.php b/tests/ServiceProviderTest.php index 4d97db1..683725c 100644 --- a/tests/ServiceProviderTest.php +++ b/tests/ServiceProviderTest.php @@ -2,20 +2,20 @@ declare(strict_types=1); -namespace Rinvex\Addressable\Test; +namespace Rinvex\Addresses\Test; use ReflectionClass; use PHPUnit\Framework\TestCase; use Illuminate\Container\Container; use Illuminate\Support\ServiceProvider; -use Rinvex\Addressable\Providers\AddressableServiceProvider; +use Rinvex\Addresses\Providers\AddressesServiceProvider; class ServiceProviderTest extends TestCase { /** Get the service provider class. */ protected function getServiceProviderClass(): string { - return AddressableServiceProvider::class; + return AddressesServiceProvider::class; } /** @test */ From 7c9ee89bd1682d55c13f42d7c878943ca83ef916 Mon Sep 17 00:00:00 2001 From: Abdelrahman Omran Date: Fri, 8 Sep 2017 21:39:40 +0200 Subject: [PATCH 65/65] Rename package rinvex/addresses from rinvex/addressable --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06718f8..bba9858 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,5 +5,11 @@ 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