How to specify the parameter name in Route.resource()?


#1

From the official documentation, this:

Route.resource('users', 'UserController')

Is equivalent to this:

Route.get('users', 'UserController.index').as('users.index')
Route.post('users', 'UserController.store').as('users.store')
Route.get('users/create', 'UserController.create').as('users.create')
Route.get('users/:id', 'UserController.show').as('users.show')
Route.put('users/:id', 'UserController.update').as('users.update')
Route.patch('users/:id', 'UserController.update')
Route.get('users/:id/edit', 'UserController.edit').as('users.edit')
Route.delete('users/:id', 'UserController.destroy').as('users.destroy')

But what if I want my parameter to be called foo instead of id? I want this for naming consistency reasons in my code.

Thank you,
Billal Begueradj


#2

Nope, there is no way to customize identifier for the resource. Adding it isn’t a big deal, but then we need to have options for nested resources too.

What sort of API you expect to define indentifier?


#3

In some of my tables, the primary key is not called id, so that is why I wish Route.resource() let me inject the parameter name I want. But as you said, this is not a big deal if this option does not exist. Thank you