# adonis-route-model-binding

> Easy route model binding in AdonisJS

Latest version **0.1.0** (published 2018-03-16) · WTFPL license · 0 weekly downloads

## Install

```sh
npm install adonis-route-model-binding
pnpm add adonis-route-model-binding
yarn add adonis-route-model-binding
bun add adonis-route-model-binding
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2018-03-16 |
| First published | 2018-03-16 |
| Weekly downloads | 0 |
| License | WTFPL |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 18.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Thomas Steinmetz |
| Maintainers | thsteinmetz |
| Keywords | route, adonis, adonisjs, adonis models, adonis route model binding |

## Links

- npm: https://www.npmjs.com/package/adonis-route-model-binding
- Repository: https://github.com/thsteinmetz/adonis-route-model-binding
- Homepage: https://github.com/thsteinmetz/adonis-route-model-binding#readme
- Issues: https://github.com/thsteinmetz/adonis-route-model-binding/issues
- npm.io page: https://npm.io/package/adonis-route-model-binding

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 0.1.0 (latest) — 2018-03-16

## README

# adonis-route-model-binding

This package just takes the example from the the [AdonisJS](https://adonisjs.com) documentation about [extending routes](https://adonisjs.com/docs/4.1/routing#_extending_routes) and adds an additional lookup parameter (the field to look up on) to it.

## Example Usage

First install this package

```bash
adonis install adonis-route-model-binding
# or
npm install --save adonis-route-model-binding
# or
yarn add adonis-route-model-binding
```

Add the RouteModelBindingProvider to your `start/app.js` file

```js
const providers = [
  ...
  'adonis-route-model-binding/providers/RouteModelBindingProvider',
]
```

Add the binding to a route that you have in your routes file:

```js
Route.get('some/route/:userId', 'UserController.show')
      .bind('App/Models/User', 'user', 'userId', 'id');
```

What does that mean? Below is an explanation of the list of parameters on the above `.bind(..)` method in order.

1. `App/Models/User` is the target model that you want to load

2. `user` is the key that this model will be bound to on the `request` object that gets passed into the controller

3. `userId` is the route parameter that we are using. The `:userId` on `some/route/:userId` in this case

4. `id` is the field we are going to look up the value of `userId` in

Now in your controller you will have access to the `user` object on the `show()` method:

```js
class UserController {
  
  async show({ request, params, user }) {
    // do something with user here
  }
  
}
```

## Changelog

### v0.1.0
- Initial release

## License
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

[WTFPL](http://www.wtfpl.net/)

---
_Source: https://npm.io/package/adonis-route-model-binding · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
