stylers / laravel-address
Laravel Address Manager
Installs: 2 104
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 6
Forks: 0
Open Issues: 0
Requires
- php: >=8.1
- illuminate/database: ~10
- illuminate/support: ~10
- laravel/legacy-factories: ^1.3.2
Requires (Dev)
- illuminate/database: ~10
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0
- phpmd/phpmd: ^2.6|^2.7|^2.8|^2.9|^2.15
- phpunit/phpunit: ^7.3|^8.0|^9.0|^10
This package is auto-updated.
Last update: 2024-11-03 15:40:38 UTC
README
Laravel version compatibility
Installation
composer require stylers/laravel-address
You can publish the migration
php artisan vendor:publish --provider="Stylers\Address\Providers\AddressServiceProvider"
After the migration has been published, you can run the migrations
php artisan migrate
Usage
use Stylers\Address\Contracts\Models\Traits\HasAddressesInterface; use Stylers\Address\Models\Traits\HasAddresses; class User extends Authenticatable implements HasAddressesInterface { use Notifiable; use HasAddresses; }
Update or Create Address
If the $type
is exists then will be update with $attributes
.
use Stylers\Address\Enums\AddressTypeEnum; $user = User::first(); $attributes = [ "country" => "Hungary", "zip_code" => "1055", "city" => "Budapest", "name_of_public_place" => "Kossuth Lajos", "type_of_public_place" => "place", "number_of_house" => "1-3", "floor" => "42", "door" => "69", "latitude" => "47.5070738", "longitude" => "19.045599", "parcel_number" => "10086/0/A/3", ]; // array $type = AddressTypeEnum::PRIMARY; // ?string $address = $user->updateOrCreateAddress($attributes, $type); // AddressInterface
Delete Address
use Stylers\Address\Enums\AddressTypeEnum; $user = User::first(); $type = AddressTypeEnum::PRIMARY; // ?string $isDeleted = $user->deleteAddress($type); // boolean
Sync Address(es)
The syncAddresses()
method delete all addressable address if $type
is not exists in $arrayOfAttributes[$type][]
.
The syncAddresses()
method create all $type
of arrayOfAttributes[$type][]
if type is not exists in addresses
table.
use Stylers\Address\Enums\AddressTypeEnum; $user = User::first(); $arrayOfAttributes = [ AddressTypeEnum::MAILING => [ "country" => "Hungary", "zip_code" => "1055", "city" => "Budapest", "name_of_public_place" => "Kossuth Lajos", "type_of_public_place" => "place", "number_of_house" => "1-3", "floor" => "42", "door" => "69", "latitude" => "47.5070738", "longitude" => "19.045599", "parcel_number" => "10086/0/A/3", ] ]; $addresses = $user->syncAddresses($arrayOfAttributes); // Collection
How to Test
$ docker run -it --rm -v $PWD:/app -w /app composer bash
$ composer install
$ ./vendor/bin/phpunit
Troubleshooting
# Fatal error: Allowed memory size of...
$ COMPOSER_MEMORY_LIMIT=-1 composer install