---
title: "The fluent builder — Attributes for Laravel | Roundly"
description: "Stage several attributes with metadata, adjust the staged set, then save alongside existing attributes or sync to replace them."
url: https://roundly-consulting.com/open-source/docs/attributes-for-laravel/fluent-builder
language: en
---

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

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

# The fluent builder

Attributes::for($model)->stage() returns a fluent writer — $model->attributes() is the same writer as model shorthand. Stage typed values and metadata, then persist them in one readable statement:

```php
use RoundlyConsulting\Attributes\Facades\Attributes;

Attributes::for($product)->stage()
    ->set('color', 'white')->meta('color', ['hex' => '#fff'])
    ->set('rating', 5)
    ->set('on_sale', true)
    ->save();

// Model shorthand: $product->attributes() is Attributes::for($product)->stage()
$product->attributes()->set('stock', 8)->save();
```

## Save or sync

- save() — attaches the staged attributes through the handle’s setMany() and keeps any others already on the model. With nothing staged it does nothing.
- sync() — goes through the handle’s sync(): attaches the staged attributes and removes every attribute that was not staged. Pass forceDelete: true to hard-delete the removed rows. With nothing staged it removes every attribute.

```php
// save(): add or update the staged attributes, keep the rest
$product->attributes()
    ->set('stock', 8)
    ->save();

// sync(): the staged set becomes the complete set
$product->attributes()
    ->set('color', 'black')
    ->set('rating', 4)
    ->sync();                      // every other attribute is soft-deleted

$product->attributes()
    ->set('color', 'black')
    ->sync(forceDelete: true);     // ...or hard-deleted
```

## Adjusting the staged set

forget() and except() drop staged names; only() keeps just the names you list. Metadata staged for a dropped name is dropped with it, and metadata staged for a name with no staged value is not persisted:

```php
$writer = $product->attributes()
    ->set('color', 'white')->meta('color', ['hex' => '#fff'])
    ->set('size', 'large')
    ->set('internal_note', 'check supplier');

$writer->forget('internal_note');   // drop one or more staged names
$writer->except('size');            // alias of forget()
$writer->only('color', 'size');     // keep just these names

$writer->save();                    // persists color (with its meta)
```

meta() accepts an array or a Collection. Each staged attribute goes through the same strict-mode, validation, uniqueness, history and event pipeline as set(), and every staged value is validated before the first write — one invalid value leaves the owner untouched. Both save() and sync() return the model.

## 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/attributes-for-laravel.md)
