|
| 1 | +# LaravelAddress |
| 2 | + |
| 3 | +[![Latest Version on Packagist][ico-version]][link-packagist] |
| 4 | +[![Total Downloads][ico-downloads]][link-downloads] |
| 5 | +[![Build Status][ico-travis]][link-travis] |
| 6 | +[![StyleCI][ico-styleci]][link-styleci] |
| 7 | + |
| 8 | +Laravel Address is a package to manage addresses that belong to your models. You can add addresses to any eloquent model with ease. |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +1. Install the package via composer: |
| 13 | + |
| 14 | + ```shell |
| 15 | + composer require bkfdev/laravel-address |
| 16 | + ``` |
| 17 | + |
| 18 | +2. Publish resources (migrations and config files): |
| 19 | + |
| 20 | + ```shell |
| 21 | + php artisan vendor:publish --provider="Bkfdev\Addressable\AddressesServiceProvider" |
| 22 | + ``` |
| 23 | + |
| 24 | +3. Run migrations: |
| 25 | + |
| 26 | + ```shell |
| 27 | + php artisan migrate |
| 28 | + ``` |
| 29 | + |
| 30 | +4. Done! |
| 31 | + |
| 32 | +## Usage |
| 33 | + |
| 34 | +To add addresses support to your eloquent models simply use `\Bkfdev\Addressable\Traits\Addressable` trait. |
| 35 | + |
| 36 | +### Manage your addresses |
| 37 | + |
| 38 | +```php |
| 39 | +// Get instance of your model |
| 40 | +$user = new \App\Models\User::find(1); |
| 41 | +
|
| 42 | +// Create a new address |
| 43 | +$user->addresses()->create([ |
| 44 | + 'label' => 'Default Address', |
| 45 | + 'country_code' => 'dz', |
| 46 | + 'street' => '56 john doe st.', |
| 47 | + 'state' => 'Canterbury', |
| 48 | + 'city' => 'Christchurch', |
| 49 | + 'postal_code' => '7614', |
| 50 | + 'latitude' => '31.2467601', |
| 51 | + 'longitude' => '29.9020376', |
| 52 | + 'is_primary' => true, |
| 53 | +]); |
| 54 | +
|
| 55 | +// Create multiple new addresses |
| 56 | +$user->addresses()->createMany([ |
| 57 | + [...], |
| 58 | + [...], |
| 59 | + [...], |
| 60 | +]); |
| 61 | +
|
| 62 | +// Find an existing address |
| 63 | +$address = app('addressable.address')->find(1); |
| 64 | +
|
| 65 | +// Update an existing address |
| 66 | +$address->update([ |
| 67 | + 'label' => 'Default Work Address', |
| 68 | +]); |
| 69 | +
|
| 70 | +// Delete address |
| 71 | +$address->delete(); |
| 72 | +
|
| 73 | +// Alternative way of address deletion |
| 74 | +$user->addresses()->where('id', 123)->first()->delete(); |
| 75 | +``` |
| 76 | +
|
| 77 | +### Manage your addressable model |
| 78 | +
|
| 79 | +The API is intuitive and very straight forward, so let's give it a quick look: |
| 80 | +
|
| 81 | +```php |
| 82 | +// Get instance of your model |
| 83 | +$user = new \App\Models\User::find(1); |
| 84 | +
|
| 85 | +// Get attached addresses collection |
| 86 | +$user->addresses; |
| 87 | +
|
| 88 | +// Get attached addresses query builder |
| 89 | +$user->addresses(); |
| 90 | +
|
| 91 | +// Scope Primary Addresses |
| 92 | +$primaryAddresses = app('addressable.address')->isPrimary()->get(); |
| 93 | +
|
| 94 | +// Scope Addresses in the given country |
| 95 | +$algerianAddresses = app('addressable.address')->inCountry('dz')->get(); |
| 96 | +
|
| 97 | +``` |
| 98 | +
|
| 99 | +## Changelog |
| 100 | +
|
| 101 | +Refer to the [Changelog](CHANGELOG.md) for a full history of the project. |
| 102 | +
|
| 103 | +## Support |
| 104 | +
|
| 105 | +Please raise a GitHub issue. |
| 106 | +
|
| 107 | +## Testing |
| 108 | +
|
| 109 | +```bash |
| 110 | +$ composer test |
| 111 | +``` |
| 112 | +
|
| 113 | +## Contributing |
| 114 | +
|
| 115 | +Please see [contributing.md](contributing.md) for details and a todolist. |
| 116 | +
|
| 117 | +## Security |
| 118 | +
|
| 119 | +If you discover any security related issues, please email [email protected] instead of using the issue tracker. |
| 120 | +
|
| 121 | +## Credits |
| 122 | +
|
| 123 | +- [Author Name][link-author] |
| 124 | +- [All Contributors][link-contributors] |
| 125 | +
|
| 126 | +## License |
| 127 | +
|
| 128 | +MIT. Please see the [license file](license.md) for more information. |
| 129 | +
|
| 130 | +[ico-version]: https://img.shields.io/packagist/v/bkfdev/laravel-address.svg?style=flat-square |
| 131 | +[ico-downloads]: https://img.shields.io/packagist/dt/bkfdev/laravel-address.svg?style=flat-square |
| 132 | +[ico-travis]: https://img.shields.io/travis/bkfdev/laravel-address/master.svg?style=flat-square |
| 133 | +[ico-styleci]: https://styleci.io/repos/12345678/shield |
| 134 | +[link-packagist]: https://packagist.org/packages/bkfdev/laravel-address |
| 135 | +[link-downloads]: https://packagist.org/packages/bkfdev/laravel-address |
| 136 | +[link-travis]: https://travis-ci.org/bkfdev/laravel-address |
| 137 | +[link-styleci]: https://styleci.io/repos/12345678 |
| 138 | +[link-author]: https://github.com/bkfdev |
| 139 | +[link-contributors]: ../../contributors |
0 commit comments