Skip to main content

Overview

Attributes can be associated to Eloquent models to allow custom data to be stored. Typically, these will be used the most with Products where different information is needed to be stored and presented to visitors. For example, a television might have the following attributes assigned…
  • Screen Size
  • Screen Technology
  • Tuner
  • Resolution

Attributes

Field Types

::: tip INFO More field types will be coming soon. :::

Models that use Attributes

  • Lunar\Models\Product
  • Lunar\Models\ProductVariant
  • Lunar\Models\Collection

Saving Attribute Data

Adding attributes to your own model

Then ensure you have a JSON field on your model’s table called attribute_data. ::: tip When loading models it is advised you eager load the attribute data required. :::

Accessing Attribute Data.

There will come times where you need to be able to retrieve the attribute data you have stored against a model. When you target the attribute_data property it will be cast as a collection and resolved into it’s corresponding field type.
If you need to just get the value for one field, you can use the translateAttribute method on the model:

Advanced usage

Attribute Groups

Attribute Groups form a collection of attributes that are logically grouped together for display purposes. A good example might be an “SEO” attribute group which has attributes for “Meta Title” and “Meta Description”.