Skip to main content
Collections group products together for storefront categories, promotions, and other purposes.

Overview

Collections provide a flexible way to group products together for any purpose: storefront categories, hero sliders, landing page features, seasonal promotions, or any other grouping a store requires. Products can be added to a collection explicitly, and collections can be nested to form a hierarchy. Each collection belongs to a collection group, allowing different sets of collections to be maintained independently for different parts of a storefront.

Collection Groups

Collection groups act as top-level containers for collections. A store might have separate groups for a main catalog, seasonal promotions, or landing page features.

Fields

A collection group cannot be deleted while it still has collections — move or delete them first, otherwise CollectionGroupActionException is thrown.

Relationships

Creating a collection group

Collections

Fields

Collections do not use soft deletes.

Relationships

Scopes

Creating a collection

Name and description

Like products, name, description, and short_description are dedicated, translatable columns rather than custom attributes, guaranteeing every collection has a real, queryable name. They are read through the translate() helper:

Nested Collections

Collections form a tree hierarchy using the lunarphp/nestedset package, a Lunar-maintained fork of kalnoy/nestedset. The tree is scoped per collection group, so each group maintains its own independent hierarchy. Child collections can be added using the appendNode method:
This produces the following hierarchy:
At least one root (parent) collection must exist before child collections can be created. This is important when using seeders to set up the initial catalog state.
The breadcrumb accessor returns the translated names of all ancestor collections, which is useful for building breadcrumb navigation:

Querying the tree

The nested set package provides many methods for working with the tree. Here are some common examples:
Refer to the lunarphp/nestedset documentation for the full API.

Products

Products are associated using a BelongsToMany relationship with a position pivot column for ordering.

Adding products

Sorting products

The sort field on a collection determines how products are ordered. Lunar ships with the following sort options:

Channels

Collections use the HasChannels trait, enabling channel-based availability with optional scheduling. See Channels for full details.

Querying by channel

Customer Groups

Collections use the HasCustomerGroups trait, enabling customer group visibility with optional scheduling. See Customers for full details.

Querying by customer group

URLs

Collections use the HasUrls trait, which automatically generates URLs when a collection is created.
See URLs for full details on managing URLs.

Media

Collections use the HasMedia trait (via Spatie Media Library), allowing images and other media to be attached.