Models
Shopper uses three models to manage attributes:| Model | Purpose |
|---|---|
Shopper\Core\Models\Attribute | The attribute definition (Color, Size, Material) |
Shopper\Core\Models\AttributeValue | Possible values for an attribute (Red, Blue, Large) |
Shopper\Core\Models\AttributeProduct | Pivot linking attributes to products with a selected value |
Shopper\Core\Models\Contracts\Attribute and uses the HasSlug trait for automatic slug generation. Unlike products or brands, the Attribute model is not configurable via config/shopper/models.php and has no admin model wrapper.
Database Schema
Attribute Table
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | bigint | no | auto | Primary key |
name | string | no | - | Attribute name |
slug | string | yes | auto | URL-friendly identifier (unique) |
description | string | yes | null | Attribute description |
type | string | no | - | Field type enum value |
icon | string | yes | null | Icon identifier |
is_enabled | boolean | no | false | Attribute visibility |
is_searchable | boolean | no | false | Include in search |
is_filterable | boolean | no | false | Show in filters |
created_at | timestamp | yes | null | Creation timestamp |
updated_at | timestamp | yes | null | Last update timestamp |
AttributeValue Table
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | bigint | no | auto | Primary key |
value | string(50) | no | - | Display value |
key | string | no | - | Unique identifier key |
position | smallint | yes | 1 | Display order |
attribute_id | bigint | no | - | Foreign key to attribute |
AttributeProduct Table (Pivot)
| Column | Type | Nullable | Description |
|---|---|---|---|
id | bigint | no | Primary key |
attribute_id | bigint | no | Foreign key to attribute |
product_id | bigint | no | Foreign key to product |
attribute_value_id | bigint | yes | Foreign key to attribute value |
attribute_custom_value | longtext | yes | Custom value for text-based attributes |
Field Types
Attributes use theFieldType enum to determine input behavior:
| Type | Database Value | Has Predefined Values | Description |
|---|---|---|---|
| Checkbox | checkbox | Yes | Multiple values can be selected |
| ColorPicker | colorpicker | Yes | Color values with picker |
| DatePicker | datepicker | No | Date input field |
| RichText | richtext | No | HTML content editor |
| Select | select | Yes | Single value selection |
| Text | text | No | Free text input |
| Number | number | No | Integer or decimal input |
Type Checking Methods
Each attribute type has helper methods to determine its behavior:hasMultipleValues() returns true for Checkbox and ColorPicker. hasSingleValue() returns true for Select. hasTextValue() returns true for Text, Number, RichText, and DatePicker. fieldsWithValues() returns the types that require predefined values.
Relationships
Values
Products
Variants (AttributeValue)
AttributeValue can be linked to product variants:Slug & Lookup
TheHasSlug trait generates unique slugs automatically and provides a findBySlug() static method:
Query Scopes
Filter attributes by their visibility and behavior flags:Status Management
Display Helpers
type_formatted returns a translated label like “Checkbox”. typesFields() returns all available types with their labels.
Working with AttributeProduct
TheAttributeProduct model provides a computed real_value accessor:
Creating Attributes
Attribute with Predefined Values
Attribute with Free Text
Assigning Attributes to Products
Retrieving Attributes
Observer Behavior
TheAttributeObserver handles cleanup when deleting:
Disabling Attribute Feature
Permissions
The admin panel generates five permissions for attribute management:| Permission | Description |
|---|---|
browse_attributes | View the attributes list |
read_attributes | View a single attribute |
add_attributes | Create new attributes |
edit_attributes | Edit existing attributes |
delete_attributes | Delete attributes |
Components
Attribute components are part of the product configuration. To customize them:config/shopper/components/product.php:
Storefront Example
Use Cases
| Attribute Type | Example | Use Case |
|---|---|---|
| Checkbox | Size | Multiple sizes available for clothing |
| ColorPicker | Color | Product color options |
| Select | Material | Single material selection |
| Text | SKU Suffix | Custom text per product |
| Number | Weight | Numeric specifications |
| DatePicker | Release Date | Product launch date |
| RichText | Care Instructions | Detailed HTML content |