### Install and publish migrations with Composer and Artisan Source: https://github.com/roundly-consulting/addresses-for-laravel/blob/main/README.md Run these commands to install the package, publish its migrations, and run them. Requires PHP 8.4 and Laravel 12 or 13. If owning models use UUID/ULID keys, set ADDRESSES_KEY_TYPE before migrating. ```bash composer require roundly-consulting/addresses-for-laravel php artisan vendor:publish --tag="addresses-migrations" php artisan migrate ``` -------------------------------- ### Add HasAddresses trait to an Eloquent model Source: https://github.com/roundly-consulting/addresses-for-laravel/blob/main/README.md Use the HasAddresses trait on any Eloquent model to enable polymorphic address relations. This example shows a Customer model. ```php use Illuminate\Database\Eloquent\Model; use RoundlyConsulting\Addresses\Traits\HasAddresses; class Customer extends Model { use HasAddresses; } ``` -------------------------------- ### Create and retrieve a primary shipping address Source: https://github.com/roundly-consulting/addresses-for-laravel/blob/main/README.md Use the Addresses facade to create a new shipping address, set it as primary (demoting the previous primary), and then retrieve it. The country code is normalized to uppercase on input, and formatted() returns a human-readable string. ```php use RoundlyConsulting\Addresses\Enums\AddressType; use RoundlyConsulting\Addresses\Facades\Addresses; Addresses::for($customer)->new() ->type(AddressType::Shipping) ->name('Home') ->primary() // demotes the previous primary shipping address ->in('Bratislava')->at('Somewhere 1')->postalCode('81101')->country('sk') ->save(); $address = Addresses::for($customer)->primary(AddressType::Shipping); $address->country_iso; // 'SK' — normalised on the way in $address->formatted(); // 'Home, Somewhere 1, 81101 Bratislava, SK' Addresses::for($customer)->ofType(AddressType::Shipping); // Collection
```