# How do I add model settings to a model?

Model settings provide a consistent way to store configurable settings against an Eloquent model. There are various steps needed to be followed to setup model settings for a model.

First, add the `\Aero\Common\Traits\CanHaveSettings` to the model and optionally define a `RELATION_KEY`:

```php
class Acme extends Model
{ 
    use \Aero\Common\Traits\CanHaveSettings;

    public const RELATION_KEY = 'acme' //optional
  
    //...
}
```

<p class="callout info">If you added a `RELATION_KEY` make sure to add it to the relation morph map.</p>

Then update create/update requests for this model to wrap the existing rules with `::getSettingRules()`:

```php
class CreateAcmeRequest extends AeroRequest
{
    public function rules(): array
    {
        return Acme::getSettingRules([
            //...
        ]);
    }
}
```

<p class="callout info">This adds the validation rules required by the model settings alongside the request's normal validation rules.</p>

Finally, after validating the requests, save the model using `saveSettings()`:

```php
$data = $request->validated();

$acme->saveSettings($data['settings'] ?? [], true);
```

For UI support, you must include the model settings partial in your views:

```html
@include('admin::settings.model-settings', ['model' => $acme ?? new Acme()])
```