Model
staudenmeir/laravel-adjacency-list package for recursive relationships:
Extending the Model
config/shopper/models.php:
Database Schema
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | bigint | no | auto | Primary key |
name | string | no | - | Category name |
slug | string | no | auto | URL-friendly identifier (unique) |
description | longtext | yes | null | Category description |
position | integer | no | 0 | Display order position |
is_enabled | boolean | no | false | Category visibility status |
icon | string | yes | null | Icon identifier |
seo_title | string(60) | yes | null | SEO meta title |
seo_description | string(160) | yes | null | SEO meta description |
metadata | json | yes | null | Additional custom data |
parent_id | bigint | yes | null | Foreign key to parent category |
created_at | timestamp | yes | null | Creation timestamp |
updated_at | timestamp | yes | null | Last update timestamp |
Hierarchical Structure
Categories support unlimited nesting levels:Relationships
Parent Category
Children Categories
Usinglaravel-adjacency-list package:
Descendant Categories
Products
Categories have a polymorphic many-to-many relationship with products:Available Tree Methods
Thelaravel-adjacency-list package provides these methods:
| Method | Description |
|---|---|
ancestors() | The model’s recursive parents |
ancestorsAndSelf() | The model’s recursive parents and itself |
bloodline() | The model’s ancestors, descendants and itself |
children() | The model’s direct children |
childrenAndSelf() | The model’s direct children and itself |
descendants() | The model’s recursive children |
descendantsAndSelf() | The model’s recursive children and itself |
parent() | The model’s direct parent |
parentAndSelf() | The model’s direct parent and itself |
rootAncestor() | The model’s topmost parent |
siblings() | The parent’s other children |
siblingsAndSelf() | All the parent’s children |
Query Scopes
Enabled Categories
Root Categories
Custom Paths
Categories automatically generate slug paths for nested URLs:Status Management
Display Helpers
Label with Path
Creating Categories
Retrieving Categories
Working with Products
Disabling Category Feature
Components
config/shopper/components/category.php: