Model Configuration
beforeCreate()
Signature
Section titled “Signature”beforeCreate() — returns void
Available in: model
Category: Callback Functions
Description
Section titled “Description”Registers method(s) that should be called before a new object is created.
Parameters
Section titled “Parameters”| Name | Type | Required | Default | Description |
|---|---|---|---|---|
methods | string | no | — | Method name or list of method names that should be called when this callback event occurs in an object’s life cycle (can also be called with the method argument). |
Examples
Section titled “Examples”// 1. Register a single callback method to run before a new object is created
// Defined inside the model's config() function
beforeCreate("setDefaults");
// 2. Register multiple callback methods to run in sequence before creation
beforeCreate("generateSlug,stampCreatedBy");
// 3. Register callbacks using the named argument
beforeCreate(methods="generateToken,normalizeEmail");