---
title: "Updating & deleting — Addresses for Laravel | Roundly"
description: "Update with Addresses::update() and a full AddressData, soft-delete and restore addresses, and clean up when an owner goes."
url: https://roundly-consulting.com/open-source/docs/addresses-for-laravel/updating-deleting
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Addresses for Laravel](https://roundly-consulting.com/open-source/docs/addresses-for-laravel.md)

# Updating & deleting

## Updating

Addresses::update() writes an AddressData onto an existing address in one transaction, promotes it when isPrimary is true, dispatches AddressUpdated (then PrimaryAddressChanged for a promotion) and returns the refreshed model. It runs UpdateAddressAction, which you can also call directly:

```php
use RoundlyConsulting\Addresses\DataTransferObjects\AddressData;
use RoundlyConsulting\Addresses\Facades\Addresses;

$address = Addresses::update($address, AddressData::make(
    city: 'Bratislava',
    street: 'Somewhere 5',
    postalCode: '81102',
    countryIso: 'SK',
    // AddressData is a full write — carry over what should not change
    name: $address->name,
    type: $address->type,
    isPrimary: $address->is_primary,
    meta: $address->meta,
));
```

The update is a full write: every DTO field replaces the stored value. Leaving out name, type, isPrimary or meta resets them — name and meta to null, type to the configured default\_type, and isPrimary to false, which demotes the address — so carry over whatever should not change, as above. Asking a soft-deleted address to become primary throws TrashedAddressException.

The write is compared against the stored row, re-read under a lock, not against the copy you pass: a stale copy still demotes a primary promoted elsewhere, overwrites a column changed behind it with the DTO’s value, and decides a type change from the stored type. Columns the DTO does not carry keep their stored values, unless you changed them on the copy without saving — those changes are written too.

A plain $address->update(\[...\]) still works, but it skips country normalisation, the primary invariant and the AddressUpdated event.

## Deleting

Addresses::delete() soft-deletes an address, so an accidental removal can be undone. AddressDeleted is dispatched from the model’s deleted hook, which runs for delete() and forceDelete() alike:

```php
use RoundlyConsulting\Addresses\Address;
use RoundlyConsulting\Addresses\Facades\Addresses;

Addresses::delete($address);                   // soft delete; dispatches AddressDeleted
$address->restore();                           // bring it back (as primary only if the slot is free)
$address->forceDelete();                       // permanent removal (dispatches AddressDeleted too)

Address::onlyTrashed()->get();                 // what was removed
$customer->addresses()->withTrashed()->get();  // including removed ones
```

Deleting the primary leaves its type without one until you promote another. The deleted address keeps its flag, so restore() brings it back as the primary — but only while no other live primary holds the owner + type slot, and then dispatches PrimaryAddressChanged; otherwise it returns as a plain address (see Primary addresses).

## When the owner is deleted

The morph column has no foreign key, so deleting an owner leaves its addresses behind. Delete them per model so AddressDeleted fires for each — a bulk $customer->addresses()->delete() also soft-deletes, but fires no model events:

```php
// addresses are not removed with their owner — there is no foreign key or cascade.
// delete them per model so AddressDeleted fires for each:
$customer->addresses->each->delete();
$customer->delete();
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/addresses-for-laravel.md)
