Helpers
Introduction
JCC Express MVC boots a set of global helpers in jcc-express-mvc/lib/Global/helpers.ts via globalHelpers(app) during app creation.
These helpers are available during request handling and in tinker (with container/providers booted).
Runtime and environment helpers
app-> container instanceenv(key, defaultValue?)-> config/env lookuprootPath(path)-> resolve project file/module path helpertap(value, callback?)now(date?)->Carboninstancestr()->Strutility class
HTTP context helpers
request()-> currentAppRequestresponse()-> currentAppResponsenext()-> currentnextfunctionview(view, options?, callback?)inertia(component, props?, option?)redirect(url, status?)back(url?)
These depend on per-request container bindings, so they are request-lifecycle helpers.
Auth and authorization helpers
auth()-> current request userGate->GateFacadecan(user, ability, model?, ...args)authorize(user, ability, ...args)
Also available:
bcrypt(value)verifyHash(value, hash)jwtSign(payload, secret, options?)jwtVerify(token, secret)
Validation and session helpers
validate(rules, customMessages?)-> proxy torequest().validate(...)session()-> current session accessor (jccSession)
For validation behavior/details, see ../The Basics/Validation.md.
Events and queue helpers
emit(event)-> dispatch framework event (Event.dispatch)dispatch(job)-> push job to queue (or delayed whenjob.delay > 0)
Example:
TypeScript
Type declarations
Global helper types are declared in jcc-express-mvc/global.d.ts, so TypeScript understands helper signatures in app code.
Notes
authis assigned twice insideglobalHelpers; the later assignment returnsrequest().user.- Helpers that rely on request bindings (
request,response,next,validate, etc.) are not meaningful before HTTP middleware bootstraps those bindings.
Summary
- Helpers are booted globally by
globalHelpers(app). - Use request helpers for ergonomic controller/service code.
- Use
emitanddispatchfor events and queues. - Use
Gate,can, andauthorizefor policy checks.
