viitortest / addressable
Provide the address book to store multiple address at one place
dev-master
2020-04-27 09:30 UTC
Requires
- php: ^7.0.0
Requires (Dev)
- phpunit/phpunit: ^8.0|^9.0
This package is not auto-updated.
Last update: 2025-05-07 04:22:12 UTC
README
Addressable is a polymorphic Laravel package, for contact management system. You can add address to any eloquent model with ease.
Installation
-
Install the package via composer:
composer require viitortest/addressable
-
Publish resources (migrations and config files):
php artisan vendor:publish --tag=address-config
-
If you need to modify table name go to below path and change table name
config/addressable.php
-
Execute migrations via the following command:
php artisan migrate
-
Done!
Usage
To add address support to your eloquent models simply use \Viitortest\Addressable\Traits\HasContacts
trait.
HasAddress
Manage your address
// Get instance of your model $user = new \App\Models\User::find(1); // address parameter are to store address. $request = [ 'formatted_address' => 'Avdhesh House, 303, opp. Gurudwara, Bodakdev, Ahmedabad, Gujarat 380054', 'latitude' => '29.00', 'longitude' => '49.00', 'order' => 1, 'extra_attributes' => ["country"=>"india","city"=>"ahmedabad","post"=>380051] ]; // Create a single address $request = [ 'formatted_address' => 'Avdhesh House, 303, opp. Gurudwara, Bodakdev, Ahmedabad, Gujarat 380054', 'latitude' => '29.00', 'longitude' => '49.00', 'order' => 1, 'extra_attributes' => ["country"=>"india","city"=>"ahmedabad","post"=>380051] ]; $user->addAddress($request); // Get attached address collection $user->getAddress; // Get attached address query builder $user->getAddress(); // Removed address $user->removeAddress();