Purpose & Overview
Adds polymorphic morphToMany category relations, query scopes (whereCategory, whereInCategories), and automatic slug lookups to any Model.
Installation & Setup
1
Install the package
bash
bun add @veap/categorizable2
Apply trait to your domain Model
models/YourModel.ts
typescript
// models/Article.ts
import { Model } from "@veap/database";
import { Categorizable } from "@veap/categorizable";
export class Article extends Categorizable(Model) {
static table = "articles";
}
// Querying with category scopes:
const articles = await Article.query()
.whereCategory("technology")
.withCategories()
.get();3
Start application
bash
bun devMigrations run automatically on boot via MigrationServiceProvider.
Keep in mind
- Uses a polymorphic `morphToMany` relation with the `categorizables` table.
- Provides query scopes: `whereCategory('tech')` and `whereInCategories(['tech', 'design'])`.
- Supports automated category name translations when integrated with @veap/translatable.
Dependencies
Veap Kernel
@veap/kernel (^0.1.0)
Required Veap Plugins
NPM Packages
@faker-js/faker@^9.4.0
Authors & Maintainers
Veap Core Team
Maintainer