Documentation / @zerotal/core / index / RouteRegistration
Interface: RouteRegistration
Defined in: router/Router.ts:237
Returned by Router.get/post/put/delete/patch — allows chaining .name() and .bind() to register the route for URL generation and model binding.
Example
Router.get('/posts/:slug', PostController, 'show').name('posts.show');
route('posts.show', { slug: 'hello' }); // → '/posts/hello'
Router.get('/users/:user', UserController, 'show').bind('user', User);
// controller: const user = ctx.model<User>('user');
Methods
name()
name(
routeName):RouteRegistration
Defined in: router/Router.ts:243
Name this route so it can be resolved to a URL with the route helper.
Parameters
routeName
string
Dot-notation name, e.g. 'posts.show'.
Returns
RouteRegistration
bind()
bind(
paramName,model):RouteRegistration
Defined in: router/Router.ts:263
Attach a model binding to a specific route parameter.
When a request matches this route, the framework calls Model.findOrFail(id)
before the controller runs and stores the result in ctx.model('paramName').
If the record does not exist, a ModelNotFoundError (404) is thrown automatically.
Parameters
paramName
string
The :param segment name (without the colon).
model
ModelClass | ModelBindingResolver
A model class with a static findOrFail(id) method,
OR a custom async resolver (value, ctx) => Promise<T>.
Returns
RouteRegistration
Example
// Model class (uses findOrFail internally):
Router.get('/users/:user', UserController, 'show').bind('user', User);
// Custom resolver — resolve by slug instead of id:
Router.get('/posts/:post', PostController, 'show')
.bind('post', (value) => Post.where('slug', value).firstOrFail());