Digging Deeper
Helpers
Introduction
JCC Express MVC registers a set of global helpers when your application boots. They are available during HTTP request handling and in tinker (with the container and providers loaded).
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()-> currentAppRequest(returns{}outside an HTTP request)response()-> currentAppResponse(returns{}outside an HTTP request)view(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. request() and response() are safe to call from code that may run outside middleware (for example pagination link builders) — they return an empty object when no request is bound.
next() is not exposed as a global helper. Use the next argument in middleware and route handlers directly.
Auth and authorization helpers
auth()->Authenticationclass (Auth.attempt,Auth.apiAttempt,Auth.logout, etc.)Gate->GateFacadecan(user, ability, model?, ...args)authorize(user, ability, ...args)
Database helpers
prisma()-> registered Prisma client singleton (whendatabase.prisma.serviceis configured orDB_ORM=prisma)typeorm()-> registered TypeORMDataSourcesingleton (whendatabase.typeorm.dataSourceis configured orDB_ORM=typeorm)
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.
Deferred tasks
defer(callback)-> run a callback after the HTTP response is sent to the client
The callback executes on the finish event of the current response, so the client never waits for it.
Errors thrown inside a deferred callback are caught and logged — they do not affect the already-sent response. See Deferred-Functions.md for full details.
Events and queue helpers
emit(event)-> dispatch framework event (Event.dispatch)dispatch(job)-> push job to queue (or delayed whenjob.delay > 0)
Example:
Type declarations
TypeScript picks up helper signatures from the jcc-express-mvc package types, so env(), request(), auth(), and the rest are recognized in application code.
Notes
- Helpers that rely on request bindings (
request,response,validate,session, etc.) are not meaningful before HTTP middleware bootstraps those bindings. request()andresponse()catch missing bindings and return{}instead of throwing.
Summary
- Helpers are registered automatically when the application starts.
- Use request helpers for ergonomic controller and service code.
- Use
emitanddispatchfor events and queues. - Use
Gate,can, andauthorizefor policy checks.