Model
The model used isShopper\Models\Brand, which extends Shopper\Core\Models\Brand. The core model provides the business logic, relationships, scopes, and slug generation. The admin model adds media collections and conversions through Spatie MediaLibrary.
The core model implements Shopper\Core\Models\Contracts\Brand and uses the HasSlug trait for automatic slug generation with collision handling, and the HasMediaCollections trait for config-driven media support.
Extending the Model
To add custom behavior, extend the admin model and update your configuration:config/shopper/models.php:
Database Schema
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | bigint | no | auto | Primary key |
name | string | no | - | Brand name |
slug | string | yes | auto | URL-friendly identifier (unique) |
website | string | yes | null | Brand’s official website URL |
description | longtext | yes | null | Brand description (supports rich text) |
position | smallint (unsigned) | no | 0 | Display order position |
is_enabled | boolean | no | false | Brand visibility status |
seo_title | string(60) | yes | null | SEO meta title |
seo_description | string(160) | yes | null | SEO meta description |
metadata | jsonb | yes | null | Additional custom data |
created_at | timestamp | yes | null | Creation timestamp |
updated_at | timestamp | yes | null | Last update timestamp |
Slug Generation
TheHasSlug trait generates unique slugs automatically. When you set the slug attribute, the trait runs it through Str::slug() and appends an incrementing suffix (-1, -2, etc.) if a collision is detected.
The trait also provides a findBySlug() static method:
Relationships
Products
A brand has many products. This is a standardHasMany relationship using the configured product model.
Query Scopes
Enabled Brands
Theenabled scope filters brands where is_enabled is true. Use it for all storefront queries to exclude draft or hidden brands.
Status Management
TheupdateStatus() method provides a convenient way to toggle brand visibility:
Media
Brands support two media collections through Spatie MediaLibrary, using the same config-driven collection names as products.| Collection | Config key | Behavior | Description |
|---|---|---|---|
| Default gallery | shopper.media.storage.collection_name | Multiple files | Brand images |
| Thumbnail | shopper.media.storage.thumbnail_collection | Single file | Brand logo |
Creating Brands
To create a brand with a logo and SEO metadata:Retrieving Brands
To get all enabled brands ordered by position:Metadata
Themetadata JSON column lets you store additional custom data that doesn’t warrant its own database column:
Configuration
Disabling Brands
If you don’t need brands in your store, disable the feature inconfig/shopper/features.php:
Permissions
The admin panel generates four permissions for brand management:| Permission | Description |
|---|---|
browse_brands | View the brands list |
read_brands | View a single brand |
add_brands | Create new brands |
edit_brands | Edit existing brands |
delete_brands | Delete brands |
Components
To customize the admin UI for brand management:config/shopper/components/brand.php:
Storefront Example
This example shows a brand listing page and a brand detail page with its published products.View Composer
For brands that appear in multiple views (header, footer, filters), use a View Composer to avoid repeating the query:AppServiceProvider: