{"id":21714623,"url":"https://github.com/lecturize/laravel-addresses","last_synced_at":"2025-04-04T11:12:32.292Z","repository":{"id":1555411,"uuid":"42934536","full_name":"Lecturize/Laravel-Addresses","owner":"Lecturize","description":"Simple address and contact management for Laravel.","archived":false,"fork":false,"pushed_at":"2024-04-28T14:04:00.000Z","size":118,"stargazers_count":198,"open_issues_count":2,"forks_count":39,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-28T10:05:42.806Z","etag":null,"topics":["laravel","laravel-addresses"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Lecturize.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-09-22T13:12:55.000Z","updated_at":"2025-02-20T08:51:14.000Z","dependencies_parsed_at":"2023-02-15T09:01:19.775Z","dependency_job_id":"f5026388-d226-45d3-b718-8512349fc380","html_url":"https://github.com/Lecturize/Laravel-Addresses","commit_stats":{"total_commits":116,"total_committers":3,"mean_commits":"38.666666666666664","dds":0.5172413793103448,"last_synced_commit":"6a7a96bc9a465e1a7d8579d1f3a3f2a3429eb42f"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lecturize%2FLaravel-Addresses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lecturize%2FLaravel-Addresses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lecturize%2FLaravel-Addresses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lecturize%2FLaravel-Addresses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lecturize","download_url":"https://codeload.github.com/Lecturize/Laravel-Addresses/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247166168,"owners_count":20894654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["laravel","laravel-addresses"],"created_at":"2024-11-26T00:37:01.773Z","updated_at":"2025-04-04T11:12:32.265Z","avatar_url":"https://github.com/Lecturize.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Latest Stable Version](https://poser.pugx.org/lecturize/laravel-addresses/v/stable)](https://packagist.org/packages/lecturize/laravel-addresses)\n[![Total Downloads](https://poser.pugx.org/lecturize/laravel-addresses/downloads)](https://packagist.org/packages/lecturize/laravel-addresses)\n[![License](https://poser.pugx.org/lecturize/laravel-addresses/license)](https://packagist.org/packages/lecturize/laravel-addresses)\n\n# Laravel Addresses\n\nSimple address and contact management for Laravel with automatical geocoding to add longitude and latitude.\n\n## Installation\n\nRequire the package from your `composer.json` file\n\n```php\n\"require\": {\n\t\"lecturize/laravel-addresses\": \"^1.1\"\n}\n```\n\nand run `$ composer update` or both in one with `$ composer require lecturize/laravel-addresses`.\n\n## Configuration \u0026 Migration\n\n```bash\n$ php artisan vendor:publish --provider=\"Lecturize\\Addresses\\AddressesServiceProvider\"\n```\n\nThis will publish the config file to `config/lecturize.php` and some migration files, that you'll have to run:\n\n```bash\n$ php artisan countries:migration\n$ php artisan migrate\n```\n\nFor migrations to be properly published ensure that you have added the directory `database/migrations` to the classmap in your projects `composer.json`.\n\nCheck out [Webpatser\\Countries](https://github.com/webpatser/laravel-countries) readme to see how to seed their countries data to your database.\n\n## Usage\n\nFirst, add our `HasAddresses` trait to your model.\n        \n```php\n\u003c?php namespace App\\Models;\n\nuse Lecturize\\Addresses\\Traits\\HasAddresses;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Post extends Model\n{\n    use HasAddresses;\n\n    // ...\n}\n?\u003e\n```\n\n##### Add an Address to a Model\n```php\n$post = Post::find(1);\n$post-\u003eaddAddress([\n    'street'     =\u003e '123 Example Drive',\n    'city'       =\u003e 'Vienna',\n    'post_code'  =\u003e '1110',\n    'country'    =\u003e 'AT', // ISO-3166-2 or ISO-3166-3 country code\n    'is_primary' =\u003e true, // optional flag\n]);\n```\n\nAlternativly you could do...\n\n```php\n$address = [\n    'street'     =\u003e '123 Example Drive',\n    'city'       =\u003e 'Vienna',\n    'post_code'  =\u003e '1110',\n    'country'    =\u003e 'AT', // ISO-3166-2 or ISO-3166-3 country code\n    'is_primary' =\u003e true, // optional flag\n];\n$post-\u003eaddAddress($address);\n```\n\nAvailable attributes are `street`, `street_extra`, `city`, `post_code`, `state`, `country`, `state`, `notes` (for internal use). You can also use custom flags like `is_primary`, `is_billing` \u0026 `is_shipping`. Optionally you could also pass `lng` and `lat`, in case you deactivated the included geocoding functionality and want to add them yourself.\n\n##### Check if Model has Addresses\n```php\nif ($post-\u003ehasAddresses()) {\n    // Do something\n}\n```\n\n##### Get all Addresses for a Model\n```php\n$addresses = $post-\u003eaddresses()-\u003eget();\n```\n\n##### Get primary/billing/shipping Addresses\n```php\n$address = $post-\u003egetPrimaryAddress();\n$address = $post-\u003egetBillingAddress();\n$address = $post-\u003egetShippingAddress();\n```\n\n##### Update an Address for a Model\n```php\n$address = $post-\u003eaddresses()-\u003efirst(); // fetch the address\n\n$post-\u003eupdateAddress($address, $new_attributes);\n```\n\n##### Delete an Address from a Model\n```php\n$address = $post-\u003eaddresses()-\u003efirst(); // fetch the address\n\n$post-\u003edeleteAddress($address); // delete by passing it as argument\n```\n\n##### Delete all Addresses from a Model\n```php\n$post-\u003eflushAddresses();\n```\n\n## Contacts\n\nFirst, add our `HasContacts` trait to your model.\n\n```php\n\u003c?php namespace App\\Models;\n\nuse Lecturize\\Addresses\\Traits\\HasContacts;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass Team extends Model\n{\n    use HasContacts;\n\n    // ...\n}\n?\u003e\n```\n\n##### Add a Contact to a Model\n\n```php\n$post = Team::find(1);\n$post-\u003eaddContact([\n    'first_name' =\u003e 'Alex',\n    'website'    =\u003e 'https://twitter.com/AMPoellmann',\n    'is_primary' =\u003e true, // optional flag\n]);\n```\n\n##### Relate Addresses with Contacts\n\nAbove all, `addresses` and `contacts` can be connected with an optional One To Many relationship. Like so you could assign multiple contacts to an address and retrieve them like so:\n\n```php\n$address = config('lecturize.addresses.model', \\Lecturize\\Addresses\\Models\\Address::class)::find(1);\n$contacts = $address-\u003econtacts;\n\nforeach ($contacts as $contact) {\n    //\n}\n```\n\n```php\n$contact = config('lecturize.contacts.model', \\Lecturize\\Addresses\\Models\\Contact::class)::find(1)\n                  -\u003econtacts()\n                  -\u003efirst();\n```\n\n```php\n$contact = config('lecturize.contacts.model', \\Lecturize\\Addresses\\Models\\Contact::class)::find(1);\n\nreturn $contact-\u003eaddress-\u003egetHtml();\n```\n\n##### Geocoding\n\nThe address model provides a method `geocode()` which will try to fetch longitude and latitude through the Google Maps API. Please make sure to add your key within the services config file at `services.google.maps.key`. If you set the option `lecturize.addresses.geocode` to `true`, the package will automatically fire the `geocode()` method whenever an addresses model is saved (precisely we hook into the `saving` event).\n\n## Changelog\n\n- [2021-02-02] **v1.0** The `geocode` configuration option now defaults to `false`.\n- [2022-05-16] **v1.1** Updated dependencies to PHP 8 and Laravel 8/9 - for older versions please refer to v1.0.\n- [2023-02-21] **v1.2** Laravel 10 support.\n- [2023-09-21] **v1.3** Support custom models for addresses and contacts, thanks to @bfiessinger. The geocoding feature now requires a Google Maps key, see 'Geocoding' above. Also, @bfiessinger has added fallback support for flags, see pull request #40 for further info.\n- [in-progress] **v1.4** Added additional contact fields to the addresses table, to allow for easier standalone usage (without the contacts model). This is intended to reduce the complexity of relationships and queries, that before were necessary e.g. to generate a shipping label from address and contact.\n\n## License\n\nLicensed under [MIT license](http://opensource.org/licenses/MIT).\n\n## Author\n\n**Handcrafted with love by [Alexander Manfred Poellmann](https://twitter.com/AMPoellmann) in Vienna \u0026amp; Rome.**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecturize%2Flaravel-addresses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flecturize%2Flaravel-addresses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flecturize%2Flaravel-addresses/lists"}